• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Deserializing JSON to LocalDate

 
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure in what forum to post...
I'm trying to help an other poster here on the forum, I managed to figure out what is going wrong, he has a textfile containing jsonobjects, each of those objects contains a date.
When trying to read the file I get this error:

In my search what could cause the error I saw a remark of someone that he got the error because he didn't deserialize the date in the jsonObject.
When I remove the date, the error is gone, so in this case that's most likely also the prob.
I've never deserialized anything, how would you do that?
 
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be helpful to see the JSON-encoded representation and the code being used to de-serialize.
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There isn't any code to deserialize yet... I wouldn't even know how to start
These are the jsonObjects:

and this is what I'm using to read the files:
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your dates aren't strings, but numerical calculations. That's not allowed in JSON. You need to put your dates between double quotes as well.
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't write the json myself it's created


I added this to my playerClass:

but I still get the same error, even when I put my date between double quotes
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That doesn't look like a legal JSON stream anyway. More valid would be:


Otherwise you have a collection of JSON snippets that are valid at the unit level but not valid as a JSON stream.
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not supossed to be seen as a collection, but all seperate jsonobjects.
Everytime the player ends a game a line is being added
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. I missed that. But we need your latest stacktrace. The only one we have is where it choked on not quoting the date strings. Which, alas, I forgot to add to my own example.
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe I should post a new question cause I maded some changes a and now the subjectline dosn't really cover my question anymore?!
I removed the LocalDate from my PlayerClass and save it now as a string.
but it seems that my jsonObject isn't bindded corectly to the javaObject, cause I'm getting nullpointers.
I'll post the whole code to make it a bit easier for you guys to help.

PlayerClass:


MenuController:

AddController:

ShowController:

Stacktrace:
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lol weird as hell... Before, cause it was ment as an quick example, aal the code was in my sample.Controller.
I knew if I would have posted it that way here, surely someone would a remark about it, so I sperated my code a bit.
I ran it again to see if the rest still worked and now everything works!?
At least allmost, no errors anymore, but the nameColumn isn't filled yet
 
Daniel Demesmaecker
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also managed to figure that out, in my object I was referring to userName, but the instance variable is name, so I changed the instance variable and adjusted the propertyValueFactory and tada
reply
    Bookmark Topic Watch Topic
  • New Topic