public static JsonNode deserializeIntoTree(String contents, String fileOrHost) { JsonNode result; try { if (isJson(contents)) { result = Json.mapper().readTree(contents); } else { result = readYamlTree(contents); } } catch (IOException e) { throw new RuntimeException("An exception was thrown while trying to deserialize the contents of " + fileOrHost + " into a JsonNode tree", e); } return result; }
T result = DeserializationUtils.deserialize(contents, file, expectedType); resolutionCache.put(ref, result); return result; JsonNode tree = DeserializationUtils.deserializeIntoTree(contents, file); result = (T) ser.definition((ObjectNode) tree, definitionPath.replace("/", "."), null); } else { result = DeserializationUtils.deserialize(tree, file, expectedType);
rootNode = mapper.readTree(data); } else { rootNode = DeserializationUtils.readYamlTree(data);
public static <T> T deserialize(Object contents, String fileOrHost, Class<T> expectedType) { T result; boolean isJson = false; if(contents instanceof String && isJson((String)contents)) { isJson = true; } try { if (contents instanceof String) { if (isJson) { result = Json.mapper().readValue((String) contents, expectedType); } else { result = Yaml.mapper().readValue((String) contents, expectedType); } } else { result = Json.mapper().convertValue(contents, expectedType); } } catch (Exception e) { throw new RuntimeException("An exception was thrown while trying to deserialize the contents of " + fileOrHost + " into type " + expectedType, e); } return result; }
rootNode = mapper.readTree(data); } else { rootNode = DeserializationUtils.readYamlTree(data);
public SwaggerDeserializationResult readWithInfo(String swaggerAsString, boolean resolve) { if (swaggerAsString == null || swaggerAsString.trim().isEmpty()) { return new SwaggerDeserializationResult().message("empty or null swagger supplied"); } try { JsonNode node; if (swaggerAsString.trim().startsWith("{")) { ObjectMapper mapper = Json.mapper(); node = mapper.readTree(swaggerAsString); } else { node = DeserializationUtils.readYamlTree(swaggerAsString); } SwaggerDeserializationResult result = new Swagger20Parser().readWithInfo(node); if (result != null) { if (resolve) { result.setSwagger(new SwaggerResolver(result.getSwagger(), new ArrayList<AuthorizationValue>(), null).resolve()); } } else { result = new SwaggerDeserializationResult().message("Definition does not appear to be a valid Swagger format"); } return result; } catch (Exception e) { return new SwaggerDeserializationResult().message("malformed or unreadable swagger supplied"); } }