Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jackson - converting java object to json - Need all key keys to upper case

 
Asif Usman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need your help on conversion of java objects to json. current the json result showing all the key in small letter case, i need it to be upper case.



and the result is

[{"flags":"1","name":"Peter","location":"London","startDate":"2012-01-06 00:00"}]

but i want results like this (all key key value should be in UPPER CASE)
[{"FLAGS":"YU","NAME":"Peter","LOCATION":"London","STARTDATE":"2012-01-06 00:00"}]

and also is it possible to get like this also (key first letter in upper case)
[{"Flags":"1","Name":"Peter","Location":"London","StartDate":"2012-01-06 00:00"}]

Can anyone help me on this.

Thanks in advance.

Regards, Asif
 
Junilu Lacar
Bartender
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
 
Asif Usman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lacar,

Thanks for the update, but i dont want to make upper case for values field, only key fields i want to make upper case.

If i use toUpperCase then the whole string will be in upper case.

I want only key to be in upper case and values should be in lower case only.
 
Junilu Lacar
Bartender
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then pass only the key to toUpperCase() and pass the value to toLowerCase()... I don't see what the problem is. Do you have any code that you wrote that is not working as you expect it to work? Without seeing what you're trying to do in code, it's kind of hard to not make assumptions and give you a helpful answer. And I don't mean the code that you already gave because that doesn't do anything at all to separate out the keys from the values and work with toUpperCase/toLowerCase. Try to write some code that isolates the keys and values first, then apply the case conversion methods.

Edit - You can look at the java.util.Scanner and/or the java.util.regex API. - Since you are using Jackson, read the API and the tutorials to see how you can isolate the keys and values. It's pretty straightforward to apply the case conversion methods from there.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic