stormpath-sdk-java
stormpath-sdk-java copied to clipboard
Jackson Serializer/Deserializer
Hi,
I'm trying to find a way to create Jackson Serializer/Deserializer for Account and Groups. I'm currently using :
public class AccountSerializer extends StdSerializer<Account> {
protected AccountSerializer() {
super(Account.class);
}
@Override
public void serialize(Account value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeStartObject();
gen.writeStringField("username", value.getUsername());
gen.writeStringField("email", value.getEmail());
gen.writeStringField("full_name", value.getFullName());
gen.writeStringField("first_name", value.getGivenName());
gen.writeStringField("last_name", value.getSurname());
gen.writeObjectField("phone", value.getCustomData().get("phone"));
gen.writeObjectField("permissions", value.getCustomData().get("permissions"));
List<String> groups = StreamSupport.stream(value.getGroups().spliterator(), false)
.map(Group::getHref).collect(Collectors.toList());
gen.writeObjectField("groups", groups);
gen.writeStringField("href", value.getHref());
gen.writeEndObject();
}
}
but this wont work for the deserialization. Is there a better way ?
Can you please help us understand the use case?
It's not quite clear to me why you'd need to serialize/deserialize when you can reference the HREF and just use the SDK to get the resource by HREF. Thoughts?
One issue with deserialization is that what you deserialize may be out of date compared to what is stored in the Stormpath api server. If so, do you want your older copy to overwrite the current api server state?
I could very well be misunderstanding what you're trying to do :)