private static RepreZenVendorExtension getFromJsonNode(ObjectNode node) { JsonNode rzve = node.get(EXTENSION_NAME); if (rzve != null) { return mapper.convertValue(rzve, RepreZenVendorExtension.class); } else { return new RepreZenVendorExtension(); } }
private static RepreZenVendorExtension getExtension(Map<String, Object> veMap, boolean create) { if (veMap == null) { return null; } Object veObj = veMap.get(EXTENSION_NAME); if (veObj == null) { if (create) { veObj = new RepreZenVendorExtension(); veMap.put(EXTENSION_NAME, veObj); } return (RepreZenVendorExtension) veObj; } else if (veObj instanceof RepreZenVendorExtension) { return (RepreZenVendorExtension) veObj; } else if (veObj instanceof Map) { // this is an RZVE object in JsonNode form, which happens because Swagger // Parser, not knowing about our // class, cannot possibly convert the value on our behalf. So we need to convert // it. RepreZenVendorExtension ve = mapper.convertValue(veObj, RepreZenVendorExtension.class); veMap.put(EXTENSION_NAME, ve); return ve; } else { return null; } }
/** * Return the RZVE object for the given model component object (or JsonNode). * <p> * If the object does not yet have a vendor extension and the * <code>create</code> parameter is true, then one is created and installed into * the object as a side-effect, with one exception: If the item is a model * component and its existing RZVE object is a JsonNode, that node is replaced * with an equivalent RZVE object, even if create if false. * <p> * Note that when the incoming item is a JsonNode, the <code>create</code> * parameter gets a bit tricky, because the newly created RZVE object cannot be * incorporated into the incoming object as a side-effect (since it is not, * itself a JsonNode object). In this case, a separate operation is required by * the caller to install the returned vendor extension into the object after * adjusting its properties. See the {@link #set(Object)) method below. */ public static RepreZenVendorExtension get(Object item, boolean create) { if (item instanceof ObjectNode) { return getFromJsonNode((ObjectNode) item); } else { Map<String, Object> veMap = getVendorExtensionMap(item); return veMap != null ? getExtension(veMap, create) : new RepreZenVendorExtension(); } }