嗨,我下面有一个序列化程序
public class RegistrationSerializer implements JsonSerializer<Registration> {
private final PresenceService presenceService;
public RegistrationSerializer(PresenceService presenceService) {
this.presenceService = presenceService;
}
@Override
public JsonElement serialize(Registration src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject element = new JsonObject();
element.addProperty("endpoint", src.getEndpoint());
element.addProperty("registrationId", src.getId());
element.add("registrationDate", context.serialize(src.getRegistrationDate()));
element.add("lastUpdate", context.serialize(src.getLastUpdate()));
element.addProperty("address", src.getAddress().getHostAddress() + ":" + src.getPort());
element.addProperty("smsNumber", src.getSmsNumber());
element.addProperty("lwM2mVersion", src.getLwM2mVersion().toString());
element.addProperty("lifetime", src.getLifeTimeInSec());
element.addProperty("bindingMode", BindingMode.toString(src.getBindingMode()));
element.add("rootPath", context.serialize(src.getRootPath()));
element.add("objectLinks", context.serialize(src.getSortedObjectLinks()));
element.add("secure", context.serialize(src.getIdentity().isSecure()));
element.add("additionalRegistrationAttributes", context.serialize(src.getAdditionalRegistrationAttributes()));
element.add("queuemode", context.serialize(src.usesQueueMode()));
if (src.usesQueueMode()) {
element.add("sleeping", context.serialize(!presenceService.isClientAwake(src)));
}
return element;
}
}
我想写一个反序列化程序版本,这样我就可以把我自己的注册对象添加到注册类中。注册类如下所示:注册类
我尝试过使用fromjson函数,但我不断收到错误,指出我没有正确地反序列化。任何帮助都将不胜感激。
暂无答案!
目前还没有任何答案,快来回答吧!