RulesObjectMapper { public String toJsonString(Map<String, Object> toSerialize) { ObjectNode mainNode = this.mapper.createObjectNode(); for (Entry<String, Object> entry : toSerialize.entrySet()) { mainNode.putPOJO(entry.getKey(), entry.getValue()); } try { return this.mapper.writeValueAsString(mainNode); } catch (Exception e) { log.error("Unable to serialize objects to JSON.", e); throw new IseException("Unable to serialize objects to JSON.", e); } } @Inject @SuppressWarnings("checkstyle:indentation")  RulesObjectMapper(ProductCachedSerializationModule poolCachedSerializationModule); String toJsonString(Map<String, Object> toSerialize); T toObject(String json, Class<T> clazz); T toObject(String json, TypeReference<T> typeref); String toJsonString(Object entity);  }
@Test public void filterConsumerIdCert() { Consumer c = new Consumer(); c.setTypeId("test-ctype"); IdentityCertificate cert = new IdentityCertificate(); cert.setCert("FILTERMEPLEASE"); cert.setKey("KEY"); c.setIdCert(cert); context.put("consumer", c); String output = objMapper.toJsonString(context); assertFalse(output.contains("FILTERMEPLEASE")); }
@Test public void filterEntitlementConsumer() { Entitlement e = new Entitlement(); Consumer c = new Consumer(); IdentityCertificate cert = new IdentityCertificate(); cert.setCert("FILTERMEPLEASE"); cert.setKey("KEY"); c.setIdCert(cert); e.setConsumer(c); context.put("entitlement", e); String output = objMapper.toJsonString(context); assertFalse(output.contains("consumer")); }
@Test public void filterEntitlementCert() { List<Entitlement> allEnts = new LinkedList<>(); Entitlement e = new Entitlement(); Set<EntitlementCertificate> entCerts = new HashSet<>(); EntitlementCertificate cert = new EntitlementCertificate(); cert.setCert("FILTERME"); cert.setKey("FILTERME"); entCerts.add(cert); e.setCertificates(entCerts); allEnts.add(e); context.put("entitlements", allEnts); String output = objMapper.toJsonString(context); assertFalse(output.contains("FILTERME")); }
@Test public void filterTimestampsOffAttributes() { Product prod = TestUtil.createProduct(); Pool p = new Pool(); p.setProduct(prod); prod.setAttribute("a", "1"); p.setAttribute("a", "1"); context.put("pool", p); String output = objMapper.toJsonString(context); assertFalse(output, output.contains("\"created\"")); assertFalse(output, output.contains("\"updated\"")); assertFalse(output, output.contains("PRODID")); }