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

no.ks.fiks.dokumentlager.klient.JsonMapper Maven / Gradle / Ivy

Go to download

Klient for opplasting, sletting og nedlasting av dokumenter fra Fiks Dokumentlager

The newest version!
package no.ks.fiks.dokumentlager.klient;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import no.ks.fiks.dokumentlager.klient.model.DokumentMetadataUpload;

import java.io.IOException;

class JsonMapper {

    private final ObjectMapper mapper = new ObjectMapper()
        .registerModule(new JavaTimeModule())
            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
            .disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE);

    String toJson(Object metadata) {
        try {
            return mapper.writeValueAsString(metadata);
        } catch (JsonProcessingException e) {
            throw new RuntimeException("Failed to serialize metadata", e);
        }
    }

     T fromJson(byte[] json, Class clazz) {
        try {
            return mapper.readValue(json, clazz);
        } catch (IOException e) {
            throw new RuntimeException("Deserialization failed", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy