CBOR: Jackson Dataformat CBOR
Gradle:
groovy
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.12.5'
Maven:
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-cbor</artifactId>
<version>2.12.5</version>
</dependency>
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import java.io.File;
import java.io.IOException;
class SerializationExample {
public static void main(String[] args) {
CBORFactory cborFactory = new CBORFactory();
ObjectMapper objectMapper = new ObjectMapper(cborFactory);
try {
objectMapper.writeValue(new File("person.cbor"), person);
} catch (IOException e) {
e.printStackTrace();
}
}
}
class Person {
private String name;
private int age;
// ...
}
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
import java.io.File;
import java.io.IOException;
class DeserializationExample {
public static void main(String[] args) {
CBORFactory cborFactory = new CBORFactory();
ObjectMapper objectMapper = new ObjectMapper(cborFactory);
try {
Person person = objectMapper.readValue(new File("person.cbor"), Person.class);
} catch (IOException e) {
e.printStackTrace();
}
}
}
class Person {
private String name;
private int age;
// ...
}