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

com.smartystreets.api.SmartySerializer Maven / Gradle / Ivy

There is a newer version: 3.18.3
Show newest version
package com.smartystreets.api;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.*;

public class SmartySerializer implements Serializer {

    public SmartySerializer() {}

    public byte[] serialize(Object obj) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        return mapper.writeValueAsBytes(obj);
    }

    public  T deserialize(byte[] payload, Class type) throws IOException {
        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        return mapper.readValue(payload, type);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy