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

org.davidmoten.oa3.codegen.http.Serializer Maven / Gradle / Ivy

There is a newer version: 0.1.22
Show newest version
package org.davidmoten.oa3.codegen.http;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;

import com.fasterxml.jackson.databind.JsonNode;

public interface Serializer {

    void serialize(Object o, String contentType, OutputStream out);

     T deserialize(Class cls, String contentType, InputStream in);
    
    /**
     * Returns the properties of object. If has no properties or is not an object
     * type that supports properties then returns an empty map. In the case of JSON
     * the map value is of an imprecise type but will serialize to JSON in an 
     * expected deterministic way using Jackson serialization (i.e the object could be 
     * an annotated Jackson object or an instance of {@link JsonNode}).
     * 
     * @param in input
     * @return map
     */
    Map properties(Object o, String contentType);
    
    default byte[] serialize(Object o, String contentType) {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        serialize(o, contentType, bytes);
        return bytes.toByteArray();
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy