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

com.gs.api.accelrx.encoding.AccelRxEncodingImpl Maven / Gradle / Ivy

The newest version!
package com.gs.api.accelrx.encoding;


import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.gs.api.accelrx.AccelRxEncoding;
import com.gs.api.accelrx.encoding.json.JsonDeserializerImpl;
import com.gs.api.accelrx.encoding.json.JsonSerializerImpl;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.jackson.DatabindCodec;
import io.vertx.rxjava3.core.Vertx;

public class AccelRxEncodingImpl implements AccelRxEncoding {
    private final Vertx vertx;
    private final AccelRxEncodingConfig encodingConfig;

    protected AccelRxEncodingImpl(Vertx vertx, AccelRxEncodingConfig encodingConfig) {
        this.vertx = vertx;
        this.encodingConfig = encodingConfig;
        initialiseJsonMapper();
    }

    public static AccelRxEncodingImpl create(Vertx vertx) {
        return new AccelRxEncodingImpl(vertx, AccelRxEncodingConfig.builder().build());
    }

    public static AccelRxEncodingImpl create(Vertx vertx, AccelRxEncodingConfig encodingConfig) {
        return new AccelRxEncodingImpl(vertx, encodingConfig);
    }

    public JsonObject jsonConfig() {
        return JsonObject.mapFrom(encodingConfig);
    }

    @Override
    public JsonSerializerImpl jsonSerializer() {
        return JsonSerializerImpl.create(vertx, encodingConfig.jsonSerializerExecutorPoolSize());
    }

    @Override
    public JsonDeserializerImpl jsonDeserializer() {
        return JsonDeserializerImpl.create(vertx, encodingConfig.jsonDeserializerExecutorPoolSize());
    }

    private void initialiseJsonMapper() {
        DatabindCodec.mapper()
                .configure(JsonParser.Feature.ALLOW_COMMENTS, true)
                .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
                .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
                .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                .setSerializationInclusion(JsonInclude.Include.NON_NULL)
                .registerModule(new JavaTimeModule());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy