boonproject / boon

Simple opinionated Java for the novice to expert level Java Programmer. Low Ceremony. High Productivity.
http://richardhightower.github.io/site/Boon/Welcome.html
Apache License 2.0
520 stars 102 forks source link

custom serializers only activated if JsonSerializerFactory.useAnnotations() set #292

Open 0xg0nz0 opened 9 years ago

0xg0nz0 commented 9 years ago

The bug is line 101 in JsonSerializerFactory. It doesn't check if customFieldSerializers is non-null as a condition for creating FieldSerializerUseAnnotationsImpl. So you have to turn on annotations in order to get custom types and field mappings even if you do not use them.

RichardHightower commented 9 years ago

Can you send me a small example that reproduces this? I can fix it faster with an example.

0xg0nz0 commented 9 years ago

If you remove setUseAnnotations(true) it will not work.

    JsonSerializerFactory jsonSerializerFactory = new JsonSerializerFactory()
            .setAsciiOnly(true)
            .setUseAnnotations(true)
            .addTypeSerializer(PasswordHolder.class, new AbstractCustomObjectSerializer<PasswordHolder>(PasswordHolder.class) {
                @Override
                public void serializeObject(JsonSerializerInternal serializer, PasswordHolder instance, CharBuf builder) {
                    builder.addQuoted(instance.getPassword());
                }
            })
            .usePropertyOnly();