com.arangodb.serde.jsonb.JsonbSerde Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsonb-serde Show documentation
Show all versions of jsonb-serde Show documentation
JsonB Serde module for ArangoDB Java Driver
The newest version!
package com.arangodb.serde.jsonb;
import com.arangodb.serde.ArangoSerde;
import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import java.nio.charset.StandardCharsets;
/**
* User data serde based on Jakarta JSON Binding (JSON-B).
*/
public class JsonbSerde implements ArangoSerde {
private final Jsonb jsonb;
public JsonbSerde() {
jsonb = JsonbBuilder.create();
}
public JsonbSerde(final JsonbConfig config) {
jsonb = JsonbBuilder.create(config);
}
@Override
public byte[] serialize(Object value) {
return jsonb.toJson(value).getBytes(StandardCharsets.UTF_8);
}
@Override
public T deserialize(byte[] content, Class type) {
return jsonb.fromJson(new String(content, StandardCharsets.UTF_8), type);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy