Menu

How to excludes properties?

Help
2007-07-31
2013-04-29
  • Eung-ju Park

    Eung-ju Park - 2007-07-31

    In json-lib 1.1, There are JSONObject.fromBean(Object object, String[] excludes) and JSONObject.fromString(String text, String[] excludes). So I can exclude properties easily. In json-lib 2.0, No excludes for JSONObject.fromObject. I found JsonConfig.setExcludes(String[] excludes). But it's global setting. I can't set excludes for specific java class or object. How can I do this? Should I implement JsonBeanProcessor?

     
    • aalmiray

      aalmiray - 2007-08-01

      The intent of JsonConfig is to make it a central point for configuration of options for serialization. You may register any set of excludes at the time you consider appropriate, taking into account that each set will override the previous one. If you need to have an empty exclude set you can pass an empty string array or call JsonConfig.reset() [will reset other values as well].

       
      • feanor

        feanor - 2007-08-28

        Hi,

        I am a little worried about this.  I currently use JSON-lib 1.0 and was upgrading to JSON-lib 2.0 (I am excited about the custom serializers). However, our application uses the exclude list on a per web request basis.  Let me explain a bit.  We use a Spring View to convert POJO's into JSON by calling JSONSerializer.toJSON.  However, several of our Spring Controllers allow the users to customize the data they see.  We use the exclude list feature in JSON-lib 1.0 to accomplish this.  That also minimizes the size of the payload on the AJAX requests.

        My concerns here is that in a multi-threaded environment I cannot safely use JsonConfig.setExcludes.  I'm also afraid of the performance implication of synchronizing calls to JsonConfig.setExcludes in my Spring View.

        Do you have any recommendations on a good workaround short of changing the application itself to behave differently?  Could I convince you to add back in an override of the exclude list to JSONSerializer.toJSON?

        Thanks,
        --Mike

         
    • aalmiray

      aalmiray - 2007-08-28

      Hi Mike,
      I'm afraid there is no workaround to handle local excludes. After a while I started to think that the previous way excludes were handled gave more freedom to the user than the actual one. Perhaps a hybrid approach may help, I definitely will give it a look and see what I can do.

      Cheers,
      Andres

       
    • feanor

      feanor - 2007-08-28

      Ok Andres.

      Thanks for the timely reply and for the consideration of a hybrid approach.
      --Mike

       
    • aalmiray

      aalmiray - 2007-09-08

      Hi Mike,
      The current 2.1-SNAPSHOT includes the fix, you can pass a JsonConfig instance (is not a singleton anymore) to the serializing methods.

      Cheers,
      Andres

       
    • feanor

      feanor - 2007-09-11

      Thanks Andre!

      I'll give it a try soon.

      Good luck on your move to the States!
      --Mike

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.