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

org.jboss.resteasy.jose.jws.util.JsonSerialization Maven / Gradle / Ivy

There is a newer version: 7.0.0.Alpha4
Show newest version
package org.jboss.resteasy.jose.jws.util;

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

import java.io.IOException;
import java.io.InputStream;

/**
 * Copied from keycloak
 *
 * Any class that extends JsonWebToken will use NON_DEFAULT inclusion
 *
 */
public class JsonSerialization {
    public static final ObjectMapper mapper = new ObjectMapper();

    static {
        mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    }

    public static String writeValueAsString(Object obj) throws IOException {
        return mapper.writeValueAsString(obj);
    }

    public static byte[] writeValueAsBytes(Object obj) throws IOException {
        return mapper.writeValueAsBytes(obj);
    }

    public static  T readValue(byte[] bytes, Class type) throws IOException {
        return mapper.readValue(bytes, type);
    }

    public static  T readValue(String bytes, Class type) throws IOException {
        return mapper.readValue(bytes, type);
    }

    public static  T readValue(InputStream bytes, Class type) throws IOException {
        return mapper.readValue(bytes, type);
    }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy