aspose file tools*
The moose likes Java in General and the fly likes Jackson - converting java object to json - Need all key keys to upper case Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Jackson - converting java object to json - Need all key keys to upper case" Watch "Jackson - converting java object to json - Need all key keys to upper case" New topic
Author

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

Asif Usman
Greenhorn

Joined: Mar 16, 2009
Posts: 12
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

Joined: Feb 26, 2001
Posts: 5298
    
  10

String.toUpperCase and converting to Title case.


Junilu - [How to Ask Questions] [How to Answer Questions]
Asif Usman
Greenhorn

Joined: Mar 16, 2009
Posts: 12
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

Joined: Feb 26, 2001
Posts: 5298
    
  10

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.
 
wood burning stoves
 
subject: Jackson - converting java object to json - Need all key keys to upper case