}
return new ObjectMapper() {
@Override
public Statement getMarshaller() {
AnonymousClassStructureBuilderImpl classStructureBuilder
= Stmt.create(context.getCodegenContext())
.newObject(parameterizedAs(Marshaller.class, typeParametersOf(JSONObject.class, toMap))).extend();
classStructureBuilder.publicOverridesMethod("getTypeHandled")
.append(Stmt.load(toMap).returnValue())
.finish();
classStructureBuilder.publicOverridesMethod("getEncodingType")
.append(Stmt.load("json").returnValue())
.finish();
classStructureBuilder.publicOverridesMethod("demarshall",
Parameter.of(Object.class, "a0"), Parameter.of(MarshallingContext.class, "a1"))
.append(Stmt.nestedCall(Stmt.newObject(toMap)
.withParameters(marshallers.toArray(new Object[marshallers.size()]))).returnValue())
.finish();
BlockBuilder<?> marshallMethodBlock = classStructureBuilder.publicOverridesMethod("marshall",
Parameter.of(Object.class, "a0"), Parameter.of(MarshallingContext.class, "a1"));
marshallToJSON(marshallMethodBlock, toMap);
marshallMethodBlock.finish();
classStructureBuilder.publicOverridesMethod("handles", Parameter.of(Object.class, "a0"))
.append(Stmt.nestedCall(Bool.and(
Bool.notEquals(Stmt.loadVariable("a0").invoke("isObject"), null),
Stmt.loadVariable("a0").invoke("isObject").invoke("get", SerializationParts.ENCODED_TYPE)
.invoke("equals", Stmt.loadVariable("this").invoke("getTypeHandled").invoke("getName"))
)).returnValue()).finish();
return classStructureBuilder.finish();
}
};
}