All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arangodb.serde.jsonb.JsonbSerde Maven / Gradle / Ivy

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