How to avoid “flexjson.JSONSerializer” convert Datetime Object to Timestamp? I want string like yyyy/MM/dd hh:mm:ss

StackOverflow https://stackoverflow.com/questions/11429885

  •  20-06-2021
  •  | 
  •  

Pergunta

I'm using flexjson.JSONSerializer to serialize Java Object, but when serializes Date property, it is converted into Timestamp:

new JSONSerializer().exclude("*.class").serialize(obj);

How can flexjson convert from Date to String of readable time?

Foi útil?

Solução

You can use DateTransformer for the same.

 new JSONDeserializer().use("person.birthdate", new DateTransformer("yyyy/MM/dd hh:mm:ss") ).deserialize( people );

Outras dicas

For the serializer you should use JSONSerializer#transform

new JSONSerializer().exclude("*.class")
    .transform(new DateTransformer("yyyy/MM/dd hh:mm:ss"), "creationDate")
    .serialize(obj);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top