mathewdenis / json-smart

Automatically exported from code.google.com/p/json-smart
0 stars 0 forks source link

improve JSONValue.toJSONString(new MyClass()) serialization of an object #33

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

will be nice to be able to configure some options for this feature ala gson.

on gson lib, you are able to 
1) write custom serializer (can be done imps JSONAware so its ok)
2) write custom exclusion strategy: method get invoked per each field, and must 
return true/false to skip/keep the field ie:
    private class MyExclusionStrategy implements ExclusionStrategy {

        public boolean shouldSkipClass(Class<?> clazz) {
            return false;
        }

        public boolean shouldSkipField(FieldAttributes f) {
            String cn = (f.getDeclaringClass().getCanonicalName() + '.' + f.getName());
            for (String s : skip)
                if (cn.contains(s)) return true;
            return false;
        }
    }
in this way, we can build a macro serializer object, that can be configured 
on-the-fly with unwanted fields.

3) probably the most important feature, be able to serializer 
private/protected/transient fields (and toggle between them). on GSON by 
default, you get the full load of all fields per each class, then you can
                .excludeFieldsWithModifiers(java.lang.reflect.Modifier.TRANSIENT)

to remove some modifiers from the serialization. This will add a great value 
imho, sometimes is useful to serialize private/package_protected fields 
(transient should be keep off, the meaning of transient is exactly 'don't 
serialize it please') but, if you think about keep the state of a bean, a 
private VAR must be serialized for sure

Original issue reported on code.google.com by ramarr...@gmail.com on 23 Nov 2012 at 2:57

GoogleCodeExporter commented 9 years ago
such a feature implementation had been Start using

net.minidev.asm.FieldFilter;

this feature is not public for the moment and only will be available in 
json-smart 2.X

I think I have to add a JsonParserFactory to complete this feature.

Original comment by uriel.chemouni on 1 Sep 2013 at 7:19

GoogleCodeExporter commented 9 years ago
Hi,

any news about this feature? i can't find any update about that in changelogs 
nor in docs.

Original comment by ramarr...@gmail.com on 2 Feb 2015 at 3:24