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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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].
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
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].
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
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
Ok Andres.
Thanks for the timely reply and for the consideration of a hybrid approach.
--Mike
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
Thanks Andre!
I'll give it a try soon.
Good luck on your move to the States!
--Mike