Hello
> private String getJsonExample(){
> Gson gson = new Gson();
> List<Webdvcr> test = Webdvcr.getDvcrByUnitNum("502");
> // returns a Webdvcr object that is extended from CayenneDataObject
> return gson.toJson(test);
> }
>
> In this example with GSON it works perfect and this is what I'm trying to get
> yours to do. getDvcrByUnitNum is a method in the class that extends my
> "_Webdvcr" class. Now what I am asking is it possible with your jjson to
> replicate the above code without using annotations? Or if it can't how could
> I replicate it using annotations. I thought I had them set correctly but it
> only returned "[,]" as the value.
The easiest way is using Annotations.
Did you use @JSON on class level too? Sounds like you missed that. Fore xample:
@JSON
public class Webdvcr extends _Webdvcr {
@JSON List<Webdvcr> getDvcrByUnitNum(String s) {};
}
The code would then look like:
private String getJsonExample() {
JSONAnnotationEncoder encoder = new JSONAnnotationEncoder();
List<Webdvcr> test = Webdvcr.getDvcrByUnitNum("502");
return encoder.encode(test);
}
Please let me know if that worked for you.
Cheers
Christian
>
> Thanks.
>
>
> -----Original Message-----
> From: Christian Grobmeier [mailto:[email protected]]
> Sent: Thursday, September 01, 2011 10:20 AM
> To: [email protected]
> Subject: Re: What JSON library are you using with cayenne?
>
> Hello David,
>
> On Thu, Sep 1, 2011 at 4:00 PM, Pipes, David <[email protected]> wrote:
>> What are you all using for your JSON library with cayenne? I am looking for
>> some feedback on what works well out of the box or with little work. I can't
>> seem to find a good JSON library that works well with cayenne and db2 on an
>> as400. My initial research pointed me to GSON (Google JSON library). This
>> worked amazingly well right out of the box on my local server (windows).
>> Once we added it to our production server on the 400 it didn't seem to work.
>> Then I tried JACKSON. It looked promising but not easily configurable with
>> parent child relationships in cayenne with circlular references.
>>
>> So, I'm looking for one of two things here. What libraries are you using or
>> has anyone had success with GSON on the as400? I would prefer to use GSON
>> for its simplicity but am also welcoming feedback on both.
>
> actually I always had problems with the other JSON libs out there, so I wrote
> my own:
> http://code.google.com/p/jjson/
> It uses plain Java without dependencies, so you have a good chance to make it
> work on AS400.
>
> You can use the @JSON annotations on the properties you want to expose as
> JSON. I use the classes for it which extend the _UnderScoreClases, overwrite
> and annotate the getters. This worked pretty well for me.
>
> Let me know if I can help more
>
> Cheers
>
--
http://www.grobmeier.de