public JsonNode getSchema(SerializerProvider paramSerializerProvider, Type paramType) throws JsonMappingException { ObjectNode localObjectNode = createSchemaNode("array", true); if (paramType != null) { paramType = paramSerializerProvider.constructType(paramType); if (paramType.isArrayType()) { paramType = ((ArrayType) paramType).getContentType().getRawClass(); if (paramType != Object.class) { break label54; } localObjectNode.set("items", JsonSchema.getDefaultSchemaNode()); } } return localObjectNode; label54: paramType = paramSerializerProvider.findValueSerializer(paramType, this._property); if ((paramType instanceof SchemaAware)) {} for (paramSerializerProvider = ((SchemaAware) paramType).getSchema(paramSerializerProvider, null); ; paramSerializerProvider = JsonSchema.getDefaultSchemaNode()) { localObjectNode.set("items", paramSerializerProvider); return localObjectNode; } }
/** * Test for [JACKSON-415] * * @since 1.7 */ public void testWithJaxb() throws Exception { ObjectMapper mapper = getJaxbMapper(); JsonSchema jsonSchema = mapper.generateJsonSchema(Address.class); ObjectNode root = jsonSchema.getSchemaNode(); // should find two properties ("city", "state"), not just one... JsonNode itemsNode = root.findValue("properties"); assertNotNull("Missing 'state' field", itemsNode.get("state")); assertNotNull("Missing 'city' field", itemsNode.get("city")); assertEquals(2, itemsNode.size()); }
@Override public JsonSchema customize(JsonSchema originalSchema) { JsonSchema jsonSchema = super.customize(originalSchema); String defaultServerUrl = System.getenv(OPENSHIFT_BROKER_HOST); if (defaultServerUrl == null || defaultServerUrl.trim().equals("")) { defaultServerUrl = "openshift.redhat.com"; } // // jsonSchema.asObjectSchema().getProperties().get("serverUrl").asStringSchema().setDefault(defaultServerUrl); ((ObjectNode) jsonSchema.getSchemaNode().get("properties").get("serverUrl")) .set("default", new TextNode(defaultServerUrl)); return jsonSchema; }
/** * The method to be called by {@link ObjectMapper} and {@link ObjectWriter} to generate <a * href="http://json-schema.org/">JSON schema</a> for given type. * * @param type The type for which to generate schema */ public JsonSchema generateJsonSchema(Class<?> type) throws JsonMappingException { if (type == null) { throw new IllegalArgumentException("A class must be provided"); } /* no need for embedded type information for JSON schema generation (all * type information it needs is accessible via "untyped" serializer) */ JsonSerializer<Object> ser = findValueSerializer(type, null); JsonNode schemaNode = (ser instanceof SchemaAware) ? ((SchemaAware) ser).getSchema(this, null) : JsonSchema.getDefaultSchemaNode(); if (!(schemaNode instanceof ObjectNode)) { throw new IllegalArgumentException( "Class " + type.getName() + " would not be serialized as a JSON object and therefore has no schema"); } return new JsonSchema((ObjectNode) schemaNode); }
public JsonNode getSchema(SerializerProvider paramSerializerProvider, Type paramType) throws JsonMappingException { ObjectNode localObjectNode1 = createSchemaNode("object", true); if ((paramType instanceof ParameterizedType)) { Object localObject = ((ParameterizedType) paramType).getActualTypeArguments(); if (localObject.length == 2) { paramType = paramSerializerProvider.constructType(localObject[0]); localObject = paramSerializerProvider.constructType(localObject[1]); ObjectNode localObjectNode2 = JsonNodeFactory.instance.objectNode(); Enum[] arrayOfEnum = (Enum[]) paramType.getRawClass().getEnumConstants(); int j = arrayOfEnum.length; int i = 0; if (i < j) { Enum localEnum = arrayOfEnum[i]; paramType = paramSerializerProvider.findValueSerializer( ((JavaType) localObject).getRawClass(), this._property); if ((paramType instanceof SchemaAware)) {} for (paramType = ((SchemaAware) paramType).getSchema(paramSerializerProvider, null); ; paramType = JsonSchema.getDefaultSchemaNode()) { localObjectNode2.set( paramSerializerProvider .getConfig() .getAnnotationIntrospector() .findEnumValue(localEnum), paramType); i += 1; break; } } localObjectNode1.set("properties", localObjectNode2); } } return localObjectNode1; }