0

I have a problem with date deserialization on client side. I have to build a simple desktop java aplication that consumes JSON. My code:

ClientConfig config = new DefaultClientConfig();
config.getClasses().add(JacksonJsonProvider.class); 
Client client = Client.create(config);

I've tried to use this solution but it doesn't work for me: How to deserialize JS date using Jackson?

I need a date in this format: "dd.MM.yyyy.", but I'm always getting this error no matter what:

Can not construct instance of java.util.Date from String value '12.10.1971.': not a valid representation (error: Can not parse date "12.10.1971.": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))

Thank you for your help.

Community
  • 1
  • 1
gajo
  • 729
  • 3
  • 10
  • 19

1 Answers1

0

I'm still thinking your linked answer should work, but here is another way which could help you.

Create a Java object for the model you are retrieving.

Let's say it is an item with 2 fields:

public class Item {
    private String name;
    private String lastModified;

    public Item() {}

    public String getName() {
        return name;
    }

    public Item setName(String name) {
        this.name = name;
        return this;
    }

    public String getLastModified() {
        return lastModified;
    }

    public Modifiable setLastModified(String lastModified) {
        this.lastModified = lastModified;
        return this;
    }
}

Jackson wouldn't try to parse it, because it would have a look into your code and knows it is a string not a date object. You could than parse it yourself.

If this is to ugly you could hold the lastModified as a date internally, because Jackson is looking for "factory" methods which are taking as a parameter a string, if no date one could be found.

Daniel Manzke
  • 310
  • 2
  • 8