You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Paul Carter-Brown <pa...@jini.guru> on 2019/03/01 17:26:42 UTC

JsonB Adapter Not Being Used

Hi,

I seem to have found another weird thing with JsonB on 8.0.0-M2

I have a ContextProvider as follows is being included in a rest app and
tells JsonB to use a custom adapter for converting ZonedDateTime to/from
String.

The weird thing is that about 10% of the time when TomEE starts it ends up
not using my adapter. This is in a boot with no load. Anyone seen this
before or have any ideas?


@Provider
@Priority(value = Integer.MIN_VALUE)
public class JsonbConfiguration implements ContextResolver<Jsonb> {

    private static final Logger log =
LoggerFactory.getLogger(JsonbConfiguration.class);
    private static Jsonb jsonb;

    public JsonbConfiguration() {
        if (jsonb != null) {
            return;
        }
        log.info("JsonbConfiguration is initialising container Jsonb");
        JsonbConfig config = new JsonbConfig()
                .withAdapters(new ZonedDateTimeAdapter())
                .withPropertyVisibilityStrategy(new
PropertyVisibilityStrategy() {
                    @Override
                    public boolean isVisible(Field field) {
                        return Modifier.isPublic(field.getModifiers())
                                ||
Modifier.isProtected(field.getModifiers());
                    }

                    @Override
                    public boolean isVisible(Method method) {
                        return Modifier.isPublic(method.getModifiers());
                    }
                });
        jsonb = JsonbBuilder.create(config);
        jsonb.fromJson("[{}]", new ParameterizedType() {
            @Override
            public Type[] getActualTypeArguments() {
                return new Type[]{Object.class};
            }

            @Override
            public Type getRawType() {
                return ArrayList.class;
            }

            @Override
            public Type getOwnerType() {
                return null;
            }

        });
        jsonb.fromJson("{}", Object.class);
        log.info("JsonbConfiguration is giving container Jsonb [{}]",
jsonb.hashCode());
    }

    @Override
    public Jsonb getContext(Class<?> type) {
        return jsonb;
    }

}



Paul Carter-Brown
Director
Jini Guru
m: +27 (0) 83 442 7179 <+27834427179>
a: 1st Floor, Golf House, Design Quarter, Cnr. William Nicol and Leslie
  Johannesburg, South Africa
w: jini.guru  e: paul@jini.guru

Disclaimer: This message and/or attachment(s) may contain
privileged, confidential and/or personal information. If you are not the
intended recipient you may not disclose or distribute any of
the information contained within this message. In such case you must
destroy this message and inform the sender of the error. Jini Guru may not
accept liability for any errors, omissions, information and viruses
contained in the transmission of this message. Any opinions, conclusions
and other information contained within this message not related to Jini
Guru official business is deemed to be that of the individual only and is
not endorsed by Jini Guru.