0

I have a JSON like below and I want to generate the Java object of the respective class by parsing it. The catch is that I don't want the value for maxtime in that object to be set as {{ Instant.MAX.toString()}}, but it should be its translated value, which means it should be +1000000000-12-31T23:59:59.999999999Z. Is there any standard library to achieve this similar requirement or I will have to write a customized code for this?

{
  "key1": "",
  "key2": "",
  "key3": {
    "maxTime": "{{ Instant.MAX.toString()}}",
    "anotherKey": "{{MyProjectUtils.getKey()}}"
  }
}

In the worst case, I am ready to replace this JSON file with some other type of file but at the end, I want a java object with translated values.

Nikunj Aggarwal
  • 754
  • 2
  • 12
  • 32
  • Could you please share the use case behind this requirement? – Smile May 10 '22 at 12:10
  • have you tried freemarker https://freemarker.apache.org/? – HariHaravelan May 10 '22 at 12:14
  • The use case is that in our project we write almost similar code but for each type of client with a different configuration to solve their need. Now our clients are increasing and we want to make it a config only solution so that we can ship faster. So we are writing a layer on our current framework which will read configs from json and create objects required for our framework. – Nikunj Aggarwal May 10 '22 at 12:17
  • I didn't use freemarker, but I can try. Does it work for JSON as well? – Nikunj Aggarwal May 10 '22 at 12:23
  • Yes @NikunjAggarwal – HariHaravelan May 10 '22 at 12:24

1 Answers1

-1

You may create a JavaBean/POJO object from a JSON file. You may adjust the members in POJO Object according to the JSON File.

here is how to create a POJO object from a JSON file.

wolfenblut
  • 131
  • 1
  • 11
  • You have explained about creating JSON from a java object but my question is about creating a java object from the JSON. – Nikunj Aggarwal May 10 '22 at 12:47
  • @NikunjAggarwal You are right, I misunderstood. I'll update my answer. However, the summary is: you can do the reverse conversion operation by creating a POJO object. [here](https://stackoverflow.com/questions/41499935/how-to-convert-the-following-json-string-to-pojo) is the answer to the reverse conversion operation. – wolfenblut May 10 '22 at 14:59
  • Its not that simple bro. Read it again. There is a catch – Nikunj Aggarwal May 10 '22 at 15:07