0

I have a question about how to preserve the order of the JSON fields of MySQL Workbench in Java?

Example: I have this value in my JSon column from my MySQL Workbench

{"URL": "www.acme.com", "poliza": "99111227", "fecIniVig": "2021-12-12" }

But when I execute my query in Java the order that I have is

First, I use a HashMap to get all the fields and keys as a table HashMap<String, Object> yourHashMap = new Gson().fromJson(resultSet.getString(3), HashMap.class);

but when I try get the fields

for(Entry<String, Object> m : yourHashMap.entrySet()){ System.out.println(m.getKey()+" "+m.getValue()); }

the output is:

  1. poliza
  2. URL
  3. fecIniVig

And I would like that the order will be as is the Json value:

  1. URL
  2. poliza
  3. fecIniVig

0 Answers0