How can I decode CBOR-encoded data that uses CBOR byte strings in Java?

45 Views Asked by At

I am sending CBOR-encoded data from one application to another. The application receiving the CBOR-encoded data is a Java application. The CBOR-encoded data was encoded with strings as byte strings, i.e., CBOR major type 2.

I thought I could do this with com.fasterxml.jackson.dataformat.cbor, but I did not find any support for decoding byte strings with this library.

I am able to decode the data in Go, using the code below. However, I am not free to change the language the application I am working on from Java to Go.

decMode, err := cbor.DecOptions{
    ByteStringToString:    cbor.ByteStringToStringAllowed,
    DefaultByteStringType: reflect.TypeOf(""),
}.DecMode()
if err != nil {
    return nil, err
}
err = decMode.Unmarshal(b.Bytes(), v)
if err != nil {
    return nil, err
}

Is there a different Java library that does have support for decoding CBOR byte strings? Or does com.fasterxml.jackson.dataformat.cbor support this, and I just failed to find details for their support in their documentation?

0

There are 0 best solutions below