protected <T> ObjectNode toJsonBase(Attribute<T> src) { ObjectNode root = mapper.createObjectNode(); root.put("visibility", src.getVisibility().name()); if (src.getRemoteIdp() != null) root.put("remoteIdp", src.getRemoteIdp()); if (src.getTranslationProfile() != null) root.put("translationProfile", src.getTranslationProfile()); ArrayNode values = root.putArray("values"); AttributeValueSyntax<T> syntax = src.getAttributeSyntax(); for (T value : src.getValues()) values.add(syntax.serialize(value)); return root; }
protected <T> void fromJsonBase(ObjectNode main, Attribute<T> target) { target.setVisibility(AttributeVisibility.valueOf(main.get("visibility").asText())); if (main.has("translationProfile")) target.setTranslationProfile(main.get("translationProfile").asText()); if (main.has("remoteIdp")) target.setRemoteIdp(main.get("remoteIdp").asText()); ArrayNode values = main.withArray("values"); List<T> pValues = new ArrayList<T>(values.size()); Iterator<JsonNode> it = values.iterator(); AttributeValueSyntax<T> syntax = target.getAttributeSyntax(); try { while (it.hasNext()) pValues.add(syntax.deserialize(it.next().binaryValue())); } catch (Exception e) { throw new InternalException("Can't perform JSON deserialization", e); } target.setValues(pValues); }