![JAR search and dependency download from the Maven repository](/logo.png)
io.payrun.helpers.SerializerHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk Show documentation
Show all versions of sdk Show documentation
Java SDK for accessing the UK Payroll API - PayRun.io
package io.payrun.helpers;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
public class SerializerHelper {
private final ObjectMapper mapper;
public SerializerHelper() {
this.mapper = new ObjectMapper();
this.mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
this.mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
this.mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
this.mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
this.mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
public String toJson(Object toBeSerialised) {
try {
return mapper.writeValueAsString(toBeSerialised);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public T fromJson(String json, Class cls) {
try {
return mapper.readValue(json, cls);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy