spring mvc - Migrate custom ObjectMapper from Jackson to Jackson2 -
i have following custom objectmapper jackson 1.9.13.
package de.outsourcing.rest.json; import com.liferay.portal.model.basemodel; import com.liferay.portal.service.servicecontext; import com.liferay.portlet.expando.model.expandobridge; import org.codehaus.jackson.jsonfactory; import org.codehaus.jackson.annotate.jsonignore; import org.codehaus.jackson.map.deserializationconfig; import org.codehaus.jackson.map.deserializerprovider; import org.codehaus.jackson.map.objectmapper; import org.codehaus.jackson.map.serializationconfig; import org.codehaus.jackson.map.serializerprovider; import org.codehaus.jackson.type.javatype; /*************************************************************************** * <b>description:</b> objectmapper add mixin annotations * make service builder entities valid jackson * deserialization * <b>created:</b>20 feb 2014 17:48:09 @author vitor silva **************************************************************************/ public class liferayobjectmapper extends objectmapper { public liferayobjectmapper() { super(); } public liferayobjectmapper(jsonfactory jf, serializerprovider sp, deserializerprovider dp, serializationconfig sconfig, deserializationconfig dconfig) { super(jf, sp, dp, sconfig, dconfig); } public liferayobjectmapper(jsonfactory jf, serializerprovider sp, deserializerprovider dp) { super(jf, sp, dp); } public liferayobjectmapper(jsonfactory jf) { super(jf); } @override public boolean candeserialize(javatype type) { deserializationconfig desconfig = copydeserializationconfig(); addmixinannotations(desconfig, type); return _deserializerprovider.hasvaluedeserializerfor(desconfig, type); } /*************************************************************************** * <b>description:</b> adds mix in annotations filter out * entity internal fields expando prevent deserialization * * <b>created:</b>20 feb 2014 16:57:31 @author vitor silva * @param desconfig **************************************************************************/ protected void addmixinannotations(deserializationconfig desconfig, javatype type) { desconfig.addmixinannotations(type.getclass(), ignoreexpandoattributesmixin.class); } abstract class ignoreexpandoattributesmixin { @jsonignore public abstract void setexpandobridgeattributes(servicecontext servicecontext); @jsonignore public abstract void setexpandobridgeattributes(basemodel<?> basemodel); @jsonignore public abstract void setexpandobridgeattributes(expandobridge expandobridge); }
}
because using spring 4 need rewrite code jackson 2 (2.3.2) changed far:
package de.outsourcing.rest.json; import com.fasterxml.jackson.annotation.jsonignore; import com.fasterxml.jackson.core.jsonfactory; import com.fasterxml.jackson.databind.deserializationconfig; import com.fasterxml.jackson.databind.javatype; import com.fasterxml.jackson.databind.objectmapper; import com.fasterxml.jackson.databind.deser.defaultdeserializationcontext; import com.fasterxml.jackson.databind.ser.defaultserializerprovider; import com.liferay.portal.model.basemodel; import com.liferay.portal.service.servicecontext; import com.liferay.portlet.expando.model.expandobridge; /*************************************************************************** * <b>description:</b> objectmapper add mixin annotations * make service builder entities valid jackson * deserialization * <b>created:</b>20 feb 2014 17:48:09 @author vitor silva **************************************************************************/ @suppresswarnings("serial") public class liferayobjectmapper extends objectmapper { public liferayobjectmapper() { super(); } public liferayobjectmapper(jsonfactory jf, defaultserializerprovider sp, defaultdeserializationcontext ddc) { super(jf, sp, ddc); } public liferayobjectmapper(jsonfactory jf) { super(jf); } @suppresswarnings("deprecation") @override public boolean candeserialize(javatype type) { deserializationconfig desconfig = getdeserializationconfig(); addmixinannotations(desconfig, type); return _deserializationcontext.hasvaluedeserializerfor(type); } /*************************************************************************** * <b>description:</b> adds mix in annotations filter out * entity internal fields expando prevent deserialization * * <b>created:</b>20 feb 2014 16:57:31 @author vitor silva * @param desconfig **************************************************************************/ protected void addmixinannotations(deserializationconfig desconfig, javatype type) { desconfig.addmixinannotations(type.getclass(), ignoreexpandoattributesmixin.class); } abstract class ignoreexpandoattributesmixin { @jsonignore public abstract void setexpandobridgeattributes(servicecontext servicecontext); @jsonignore public abstract void setexpandobridgeattributes(basemodel<?> basemodel); @jsonignore public abstract void setexpandobridgeattributes(expandobridge expandobridge); }
}
the method
protected void addmixinannotations(deserializationconfig desconfig, javatype type) { desconfig.addmixinannotations(type.getclass(), ignoreexpandoattributesmixin.class);
is not valid. specific .addmixinannotations not available in jackson2 obejct deserializationconfig.
how must change jackson2 ???
Comments
Post a Comment