@Test public void testMarshaling() { ff4j.setAuthorizationsManager(new AuthorizationsManager() { public String toJson() { return "dummy"; } public Set<String> listAllPermissions() { return new HashSet<>(); } public Set<String> getCurrentUserPermissions() { return new HashSet<>(); } public String getCurrentUserName() { return "dummy"; } }); Map<String, Event> events = new HashMap<>(); events.put("e1", new EventBuilder(ff4j).name("f1").build()); events.put("e2", new EventBuilder(ff4j).name("f2").build()); for (String key : events.keySet()) { Event e1 = EventJsonParser.parseEvent(events.get(key).toJson()); Assert.assertEquals(events.get(key).getName(), e1.getName()); Assert.assertTrue(events.get(key).compareTo(e1) == 0); } }
@SuppressWarnings("unchecked") public static Event parseEvent(String json) { try { return parseEventMap(objectMapper.readValue(json, HashMap.class)); } catch (IOException e) { throw new IllegalArgumentException("Cannot parse json as Event " + json, e); } }
EventJsonParser { @SuppressWarnings("unchecked") public static Event parseEvent(String json) { try { return parseEventMap(objectMapper.readValue(json, HashMap.class)); } catch (IOException e) { throw new IllegalArgumentException("Cannot parse json as Event " + json, e); } } }
EventJsonParser { @SuppressWarnings("unchecked") public static Event parseEvent(String json) { try { return parseEventMap(objectMapper.readValue(json, HashMap.class)); } catch (IOException e) { throw new IllegalArgumentException("Cannot parse json as Event " + json, e); } } private  EventJsonParser(); }
EventJsonParser { @SuppressWarnings("unchecked") public static Event parseEvent(String json) { try { return parseEventMap(objectMapper.readValue(json, HashMap.class)); } catch (IOException e) { throw new IllegalArgumentException("Cannot parse json as Event " + json, e); } } private  EventJsonParser(); @SuppressWarnings("unchecked") static Event parseEvent(String json); static String eventArrayToJson(Event[] events); @SuppressWarnings("unchecked") static Event[] parseEventArray(String json); }
EventJsonParser { @SuppressWarnings("unchecked") public static Event parseEvent(String json) { try { return parseEventMap(objectMapper.readValue(json, HashMap.class)); } catch (IOException e) { throw new IllegalArgumentException("Cannot parse json as Event " + json, e); } } private  EventJsonParser(); @SuppressWarnings("unchecked") static Event parseEvent(String json); static String eventArrayToJson(Event[] events); @SuppressWarnings("unchecked") static Event[] parseEventArray(String json);  }