Menu

How to remove "class" from json string?

Help
2007-09-05
2013-03-19
  • Son KwonNam

    Son KwonNam - 2007-09-05

    Whenever serialize class objects, there is always class: "ClassName" thing.
    I think it's not good, our user can see class tree from json response.

    I tried serializer.exclude("class");.

    But it works only for the first object's class. If the class(Java bean) has another Java beans as it's children, children's "class" attributes are always shown.

    I hope there is an option for removing "class"

    Thank you.
    KwonNam.

     
    • Charlie Hubbard

      Charlie Hubbard - 2007-09-06

      KwonNam,

      Right now there isn't an easy way to block the class attribute from being written to the string.  The next version of flexjson is a big change and allows more flexible exclusions like taking out the class attribute from the json stream by doing something like:

      new JSONSerializer().exclude("*.class").serialize( object );

      For the time being you'll need to block it from each class you serialize.  I know it's not optimal, but the fix is coming soon.  I just haven't had much time to dedicate to putting the finishing touches on the release.

      Thanks,
      Charlie

       
    • Charlie Hubbard

      Charlie Hubbard - 2007-09-27

      The latest release has support for wildcards which will allow you to specify:

      new JSONSerializer().exclude("*.class").serialize( obj );

      Enjoy!

      Charlie

       

Log in to post a comment.

MongoDB Logo MongoDB