FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
310 stars 133 forks source link

[CBOR] examples for parsing cbor #118

Closed naveenkumarmarri closed 6 years ago

naveenkumarmarri commented 6 years ago

I'm streaming data from a CoAP endpoint and receiving data in CBOR format. I'm checking if I can use jackson library for decoding CBOR but couldn't find any examples for getting started. Can someone help me out?

cowtowncoder commented 6 years ago

First of all: in future please ask usage questions on mailing list; issue tracker is for reporting problems:

https://groups.google.com/forum/#!forum/jackson-user

All access is using standard streaming API and/or databind API, so examples for JSON should work, with just one modification: instead of JsonFactory, you need to use CBORFactory (which is a sub-class of JsonFactory).

So, either you create CBORFactory and use streaming API directly (keeping in mind that only byte-based sources/targets can be used). Or, you create ObjectMapper like so:

ObjectMapper mapper = new ObjectMapper(new CBORFactory());

to make databind read/write CBOR instead of json.