JSONMapParser extends BasicParser { @Override public void configure(Map<String, Object> config) { setReadCharset(config); String strategyStr = (String) config.getOrDefault(MAP_STRATEGY_CONFIG, MapStrategy.DROP.name()); mapStrategy = MapStrategy.valueOf(strategyStr); overrideOriginalString = (Boolean) config.getOrDefault(OVERRIDE_ORIGINAL_STRING, false); if (config.containsKey(JSONP_QUERY)) { typeRef = new TypeRef<List<Map<String, Object>>>() { }; jsonpQuery = (String) config.get(JSONP_QUERY); if (!StringUtils.isBlank(jsonpQuery) && config.containsKey(WRAP_JSON)) { Object wrapObject = config.get(WRAP_JSON); if (wrapObject instanceof String) { wrapJson = Boolean.valueOf((String)wrapObject); } else if (wrapObject instanceof Boolean) { wrapJson = (Boolean) config.get(WRAP_JSON); } String entityName = (String)config.get(WRAP_ENTITY_NAME); if (!StringUtils.isBlank(entityName)) { wrapEntityName = entityName; } } Configuration.setDefaults(new Configuration.Defaults() { private final JsonProvider jsonProvider = new JacksonJsonProvider(); private final MappingProvider mappingProvider = new JacksonMappingProvider(); @Override public JsonProvider jsonProvider() { return jsonProvider; } @Override public MappingProvider mappingProvider() { return mappingProvider; } @Override public Set<Option> options() { return EnumSet.of(Option.SUPPRESS_EXCEPTIONS); } }); if (CacheProvider.getCache() == null) { CacheProvider.setCache(new LRUCache(100)); } } }  @Override void configure(Map<String, Object> config); @Override void init(); @Override @SuppressWarnings("unchecked") List<JSONObject> parse(byte[] rawMessage); static final String MAP_STRATEGY_CONFIG; static final String JSONP_QUERY; static final String WRAP_JSON; static final String WRAP_ENTITY_NAME; static final String DEFAULT_WRAP_ENTITY_NAME; static final String OVERRIDE_ORIGINAL_STRING; }
@Test public void getsReadCharsetFromConfig() { Map<String, Object> config = new HashMap<>(); config.put(MessageParser.READ_CHARSET, StandardCharsets.UTF_16.toString()); parser.configure(config); assertThat(parser.getReadCharset(), equalTo(StandardCharsets.UTF_16)); }
@Test public void getsReadCharsetFromDefault() { Map<String, Object> config = new HashMap<>(); parser.configure(config); assertThat(parser.getReadCharset(), equalTo(StandardCharsets.UTF_8)); }