Im having trouble in understanding the way lambda works or how to implement the suggestion,
I have this code
JsonSerializer<Date> ser = new JsonSerializer<Date>() {
@Override
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
return src == null ? null : new JsonPrimitive(src.getTime());
}
};
And I tried to follow the suggestion like so:
JsonDesializer<Date> ser = (Date src, Type typeOfSrc,
JsonSerializationContext context) -> src == null ? null : new JsonPrimitive(src.getTime());
But that doesn't compile, can someone help me a bit? thanks:)
You have a typo:
JsonDesializer
-> JsonSerializer
This compiles:
JsonSerializer<Date> ser
= (Date src, Type typeOfSrc, JsonSerializationContext context) -> src == null ? null : new JsonPrimitive(src.getTime());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.