com.alachisoft.ncache.serialization.JSON.DefaultNCacheMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-serialization Show documentation
Show all versions of nc-serialization Show documentation
Internal package of Alachisoft.
package com.alachisoft.ncache.serialization.JSON;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder;
/**
* This class handles parsing of JSON. It generates the same JSON as being generated in .NET
*/
class DefaultNCacheMapper extends ObjectMapper {
private static final String TYPE_PROPERTY = "$type"; // this is the same attribute name as it occurs in .NET
public DefaultNCacheMapper(boolean isTypeEnabled) {
super();
// if an attribute is missing during deserialization, no exception will be thrown and the attribute will be left null
this.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
// adds type to serialization
if(isTypeEnabled) {
// this custom type resolver is being written to match JSON between Java and .NET
StdTypeResolverBuilder typer = new NCacheTypeResolverBuilder(ObjectMapper.DefaultTyping.NON_FINAL)
.init(JsonTypeInfo.Id.CUSTOM, null)
.inclusion(JsonTypeInfo.As.PROPERTY)
.typeProperty(TYPE_PROPERTY);
this.setDefaultTyping(typer);
}
}
}