मैं निम्नलिखित जीएसएस क्रमबद्धता को जैक्सन क्रमबद्धता में बदलने की कोशिश कर रहा हूं। कृपया मुझे बताएं कि इसे जैक्सनजैक्सन का उपयोग कर कस्टम क्रमबद्धता/deserialization कैसे करें?
public class AbstractElementAdapter
implements JsonSerializer<AbstractElement>, JsonDeserializer<AbstractElement>
{
@Override
public JsonElement serialize(AbstractElement src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject result = new JsonObject();
JsonObject properties = context.serialize(src, src.getClass()).getAsJsonObject();
if (src instanceof TruncatedElement) {
result.add("type", new JsonPrimitive(((TruncatedElement) src).getClassName()));
properties.remove("className");
} else {
result.add("type", new JsonPrimitive(src.getClass().getSimpleName()));
}
result.add("properties", properties);
return result;
}
@Override
public AbstractElement deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = json.getAsJsonObject();
String type = jsonObject.get("type").getAsString();
JsonElement element = jsonObject.get("properties");
try {
return context.deserialize(element, Class.forName("com.zreflect.emyed.whiteboard.model.element." + type));
} catch (ClassNotFoundException cnfe) {
throw new JsonParseException("Unknown element type: " + type, cnfe);
}
}
}
कहाँ AbstractDocument.AbstractElement मिल गया? हमारे पास केवल सार तत्व श्रेणी है। – user1595858
और यदि केवल सार तत्व का उपयोग करें, तो यह अनंत लूप – user1595858
में जाता है क्षमा करें, यह केवल सार तत्व था, ऑटोमपोर्ट ने दूसरे को जोड़ा –