1

Upon trying to parse a JSON that contained two string properties of the form "yyyy-mm-dd", I get the following error:

com.google.gson.JsonSyntaxException: java.text.ParseException: Unparseable date: "2017-08-07"

I use ReimbursementRequest rr = gson.fromJson(req.getReader(), ReimbursementRequest.class); to parse them, where gson is a public static instance set to new Gson(). Will I need to define gson another way, and if so, how?

3
  • May we see the code for ReimbursementRequest, assuming it can easily fit? Commented Dec 10, 2017 at 10:27
  • It contains a class that contains the Dates. Commented Dec 10, 2017 at 10:28
  • 1
    Even though you have already answered your own question, I think you should still include an MCVE in this question so that future readers with a similar problem will benefit. Commented Dec 10, 2017 at 10:34

1 Answer 1

1

Instead of using the vanilla new Gson(), use new GsonBuilder().setDateFormat('yyyy-MM-dd').create(); // and it worked like a charm

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.