diff --git a/modules/swagger-parser/src/main/java/io/swagger/parser/Swagger20Parser.java b/modules/swagger-parser/src/main/java/io/swagger/parser/Swagger20Parser.java index f36920b5a7..a2825b5a0e 100644 --- a/modules/swagger-parser/src/main/java/io/swagger/parser/Swagger20Parser.java +++ b/modules/swagger-parser/src/main/java/io/swagger/parser/Swagger20Parser.java @@ -161,7 +161,17 @@ public Swagger read(JsonNode node) throws IOException { if (node == null) { return null; } - - return Json.mapper().convertValue(node, Swagger.class); + try { + // try first core deserializer, to ensure unchanged behaviour for working specs + return Json.mapper().convertValue(node, Swagger.class); + } catch (Exception e) { + LOGGER.error("Exception deserializing via core Json.mapper(), trying parser deserialization"); + SwaggerDeserializationResult result = (new SwaggerDeserializer()).deserialize(node); + Swagger convertValue = result.getSwagger(); + if (System.getProperty("debugParser") != null) { + LOGGER.info("\n\nSwagger Tree convertValue : \n" + ReflectionToStringBuilder.toString(convertValue, ToStringStyle.MULTI_LINE_STYLE) + "\n\n"); + } + return convertValue; + } } }