Java Code Examples for com.fasterxml.jackson.databind.ObjectMapper#writer()

The following examples show how to use com.fasterxml.jackson.databind.ObjectMapper#writer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FieldDocumentationGeneratorTest.java    From spring-auto-restdocs with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateDocumentationWithTags() throws Exception {
    // given
    ObjectMapper mapper = createMapper();
    mockFieldComment(BasicTypes.class, "string", "A string");
    mockFieldTag(BasicTypes.class, "string", "see", "this");
    mockFieldComment(BasicTypes.class, "bool", "A boolean");
    mockFieldTag(BasicTypes.class, "bool", "see", "<a href=\"xyz\">docs</a>");

    FieldDocumentationGenerator generator =
            new FieldDocumentationGenerator(mapper.writer(), mapper.getDeserializationConfig(),
                    javadocReader, constraintReader, typeMapping, SnippetTranslationManager.getDefaultResolver(),
                    null);
    Type type = BasicTypes.class;

    // when
    List<ExtendedFieldDescriptor> result = cast(generator
            .generateDocumentation(type, mapper.getTypeFactory()).values());
    // then
    assertThat(result.size(), is(4));
    assertThat(result.get(0),
            is(descriptor("string", "String", "A string<br>See this.", "true")));
    assertThat(result.get(1),
            is(descriptor("bool", "Boolean", "A boolean<br>See <a href=\"xyz\">docs</a>.",
                    "true")));
}
 
Example 2
Source File: FieldDocumentationGeneratorTest.java    From spring-auto-restdocs with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateDocumentationForBasicTypes() throws Exception {
    // given
    ObjectMapper mapper = createMapper();
    mockFieldComment(BasicTypes.class, "string", "A string");
    mockFieldComment(BasicTypes.class, "bool", "A boolean");
    mockFieldComment(BasicTypes.class, "number", "An integer");
    mockFieldComment(BasicTypes.class, "decimal", "A decimal");

    FieldDocumentationGenerator generator =
            new FieldDocumentationGenerator(mapper.writer(), mapper.getDeserializationConfig(),
                    javadocReader, constraintReader, typeMapping, SnippetTranslationManager.getDefaultResolver(),
                    null);
    Type type = BasicTypes.class;

    // when
    List<ExtendedFieldDescriptor> result = cast(generator
            .generateDocumentation(type, mapper.getTypeFactory()).values());
    // then
    assertThat(result.size(), is(4));
    assertThat(result.get(0), is(descriptor("string", "String", "A string", "true")));
    assertThat(result.get(1), is(descriptor("bool", "Boolean", "A boolean", "true")));
    assertThat(result.get(2), is(descriptor("number", "Integer", "An integer", "true")));
    assertThat(result.get(3), is(descriptor("decimal", "Decimal", "A decimal", "true")));
}
 
Example 3
Source File: PathController.java    From odo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@RequestMapping(value = "/api/path", method = RequestMethod.GET)
@ResponseBody
public String getPathsForProfile(Model model, String profileIdentifier,
                                 @RequestParam(value = "typeFilter[]", required = false) String[] typeFilter,
                                 @RequestParam(value = "clientUUID", defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID) throws Exception {
    int profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);
    List<EndpointOverride> paths = PathOverrideService.getInstance().getPaths(profileId, clientUUID, typeFilter);

    HashMap<String, Object> jqReturn = Utils.getJQGridJSON(paths, "paths");

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.addMixInAnnotations(Object.class, ViewFilters.GetPathFilter.class);
    String[] ignorableFieldNames = {"possibleEndpoints", "enabledEndpoints"};
    FilterProvider filters = new SimpleFilterProvider().addFilter("Filter properties from the PathController GET",
                                                                  SimpleBeanPropertyFilter.serializeAllExcept(ignorableFieldNames));

    ObjectWriter writer = objectMapper.writer(filters);

    return writer.writeValueAsString(jqReturn);
}
 
Example 4
Source File: FieldDocumentationGeneratorTest.java    From spring-auto-restdocs with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateDocumentationForRequiredProperties() throws Exception {
    // given
    ObjectMapper mapper = createMapper();
    mockFieldComment(RequiredProperties.class, "string", "A string");
    mockFieldComment(RequiredProperties.class, "number", "An integer");

    FieldDocumentationGenerator generator =
            new FieldDocumentationGenerator(mapper.writer(), mapper.getDeserializationConfig(),
                    javadocReader, constraintReader, typeMapping, SnippetTranslationManager.getDefaultResolver(),
                    null);
    Type type = RequiredProperties.class;

    // when
    List<ExtendedFieldDescriptor> result = cast(generator
            .generateDocumentation(type, mapper.getTypeFactory()).values());
    // then
    assertThat(result.size(), is(2));
    assertThat(result.get(0), is(descriptor("string", "String", "A string", "false")));
    assertThat(result.get(1), is(descriptor("number", "Integer", "An integer", "false")));
}
 
Example 5
Source File: DataLayerUtil.java    From AEM-DataLayer with Apache License 2.0 6 votes vote down vote up
public static final String toJSON(DataLayer dataLayer) {
	ObjectMapper objectMapper = new ObjectMapper();
	objectMapper.setDateFormat(new SimpleDateFormat(DataLayerConstants.DATE_FORMAT));

	ObjectWriter writer = null;
	if (dataLayer.getConfig().getPrettyPrint()) {
		writer = objectMapper.writerWithDefaultPrettyPrinter();
	} else {
		writer = objectMapper.writer();
	}
	try {
		return writer.writeValueAsString(dataLayer);
	} catch (JsonProcessingException e) {
		log.error("Exception writing DataLayer to JSON", e);
		return "{\"error\":true}";
	}
}
 
Example 6
Source File: SnsNotificationSender.java    From data-highway with Apache License 2.0 5 votes vote down vote up
public SnsNotificationSender(AmazonSNSAsync sns, TopicArnFactory topicArnFactory, MessageFactory messageFactory) {
  log.info("Starting SNS notifier.");
  this.sns = sns;
  this.topicArnFactory = topicArnFactory;
  this.messageFactory = messageFactory;
  ObjectMapper mapper = new ObjectMapper();
  mapper.setSerializationInclusion(Include.NON_NULL);
  objectWriter = mapper.writer();
}
 
Example 7
Source File: AbstractMarkerMixInTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    final ObjectMapper log4jObjectMapper = newObjectMapper();
    writer = log4jObjectMapper.writer();
    reader = log4jObjectMapper.readerFor(Log4jMarker.class);
    MarkerManager.clear();
}
 
Example 8
Source File: JacksonJsonLayout.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
protected ObjectWriter createConfiguredWriter(List<JacksonMixIn> mixins) {

            ObjectMapper objectMapper = createDefaultObjectMapper();
            objectMapper.registerModule(new ExtendedLog4j2JsonModule());

            if (useAfterburner) {
                // com.fasterxml.jackson.module:jackson-module-afterburner required here
                new JacksonAfterburnerModuleConfigurer().configure(objectMapper);
            }

            for (JacksonMixIn mixin : mixins) {
                objectMapper.addMixIn(mixin.getTargetClass(), mixin.getMixInClass());
            }

            ValueResolver valueResolver = createValueResolver();

            for (VirtualProperty property : virtualProperties) {
                if (!property.isDynamic()) {
                    property.setValue(valueResolver.resolve(property.getValue()));
                }
            }

            SerializationConfig customConfig = objectMapper.getSerializationConfig()
                    .with(new JacksonHandlerInstantiator(
                            virtualProperties,
                            valueResolver,
                            virtualPropertyFilters
                    ));

            objectMapper.setConfig(customConfig);

            return objectMapper.writer(new MinimalPrettyPrinter());

        }
 
Example 9
Source File: JsonSerializer.java    From gtfs-validator with MIT License 5 votes vote down vote up
/**
 * Create a JSON serializer for these validation results.
 * @param results
 */
public JsonSerializer (FeedValidationResultSet results) {
	super(results);
	mapper = new ObjectMapper();
	mapper.addMixInAnnotations(Rectangle2D.class, Rectangle2DMixIn.class);
	SimpleModule deser = new SimpleModule();
	deser.addDeserializer(Rectangle2D.class, new Rectangle2DDeserializer());
	mapper.registerModule(deser);
	SimpleFilterProvider filters = new SimpleFilterProvider();
	filters.addFilter("bbox", SimpleBeanPropertyFilter.filterOutAllExcept("west", "east", "south", "north"));
	writer = mapper.writer(filters);
}
 
Example 10
Source File: JsonTargetConfigurationSerializer.java    From buck with Apache License 2.0 5 votes vote down vote up
public JsonTargetConfigurationSerializer(
    Function<String, UnconfiguredBuildTarget> buildTargetProvider) {
  this.buildTargetProvider = buildTargetProvider;
  ObjectMapper objectMapper = ObjectMappers.createWithEmptyBeansPermitted();
  SimpleModule targetConfigurationModule = new SimpleModule();
  targetConfigurationModule.addSerializer(
      BuildTarget.class, new BuildTargetSimpleSerializer(BuildTarget.class));
  objectMapper.registerModule(targetConfigurationModule);

  objectReader = objectMapper.reader();
  objectWriter = objectMapper.writer();
}
 
Example 11
Source File: FieldDocumentationGeneratorTest.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateDocumentationForRecursiveTypes() throws Exception {
    // given
    ObjectMapper mapper = createMapper();
    FieldDocumentationGenerator generator = new FieldDocumentationGenerator(mapper.writer(),
            mapper.getDeserializationConfig(), javadocReader, constraintReader, typeMapping,
            SnippetTranslationManager.getDefaultResolver(), null);
    Type type = RecursiveType.class;

    // when
    List<ExtendedFieldDescriptor> result = cast(generator
            .generateDocumentation(type, mapper.getTypeFactory()).values());

    // then
    assertThat(result.size(), is(16));
    assertThat(result.get(0), is(descriptor("sub1", "Array[Object]", "", "true")));
    assertThat(result.get(1), is(descriptor("sub2", "Object", "", "true")));
    assertThat(result.get(2), is(descriptor("sub3", "Array[Object]", "", "true")));
    assertThat(result.get(3), is(descriptor("sub4", "Object", "", "true")));
    assertThat(result.get(4), is(descriptor("sub5", "Array[Object]", "", "true")));
    assertThat(result.get(5), is(descriptor("sub6", "Object", "", "true")));
    assertThat(result.get(6), is(descriptor("sub7", "Array[Object]", "", "true")));
    assertThat(result.get(7), is(descriptor("sub7[].sub1", "Array[Object]", "", "true")));
    assertThat(result.get(8), is(descriptor("sub7[].sub2", "Object", "", "true")));
    assertThat(result.get(9), is(descriptor("sub7[].sub3", "Array[Object]", "", "true")));
    assertThat(result.get(10), is(descriptor("sub7[].sub4", "Object", "", "true")));
    assertThat(result.get(11), is(descriptor("sub8", "Object", "", "true")));
    assertThat(result.get(12), is(descriptor("sub8.sub1", "Array[Object]", "", "true")));
    assertThat(result.get(13), is(descriptor("sub8.sub2", "Object", "", "true")));
    assertThat(result.get(14), is(descriptor("sub8.sub3", "Array[Object]", "", "true")));
    assertThat(result.get(15), is(descriptor("sub8.sub4", "Object", "", "true")));
}
 
Example 12
Source File: ConnectionInformationSerializer.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new ConnectionInformationSerializer
 *
 * @param objectMapper The preconfigured objectMapper
 */
private ConnectionInformationSerializer(ObjectMapper objectMapper) {
	ValidationUtil.requireNonNull(objectMapper, "objectMapper");
	this.objectMapper = objectMapper;
	this.objectWriter = objectMapper.writer();
	ObjectReader reader = objectMapper.reader();
	this.connectionStatisticsReader = reader.forType(ConnectionStatistics.class);
	this.connectionConfigurationReader = reader.forType(ConnectionConfiguration.class);
}
 
Example 13
Source File: FieldDocumentationGeneratorTest.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
@Test
public void testGenerateDocumentationForNestedTypes() throws Exception {
    // given
    ObjectMapper mapper = createMapper();
    mockFieldComment(FirstLevel.class, "second", "2nd level");
    mockFieldComment(SecondLevel.class, "third", "3rd level");
    mockFieldComment(ThirdLevel.class, "fourth", "4th level");
    mockFieldComment(FourthLevel.class, "fifth", "5th level");
    mockFieldComment(FifthLevel.class, "last", "An integer");

    FieldDocumentationGenerator generator =
            new FieldDocumentationGenerator(mapper.writer(),
                    mapper.getDeserializationConfig(), javadocReader, constraintReader, typeMapping,
                    SnippetTranslationManager.getDefaultResolver(), null);
    Type type = FirstLevel.class;

    // when
    List<ExtendedFieldDescriptor> result = cast(generator
            .generateDocumentation(type, mapper.getTypeFactory()).values());

    // then
    assertThat(result.size(), is(5));
    assertThat(result.get(0),
            is(descriptor("second", "Object", "2nd level", "true")));
    assertThat(result.get(1),
            is(descriptor("second.third", "Array[Object]", "3rd level", "true")));
    assertThat(result.get(2),
            is(descriptor("second.third[].fourth", "Object", "4th level", "true")));
    assertThat(result.get(3),
            is(descriptor("second.third[].fourth.fifth", "Array[Object]", "5th level",
                    "true")));
    assertThat(result.get(4),
            is(descriptor("second.third[].fourth.fifth[].last", "Integer", "An integer",
                    "true")));
}
 
Example 14
Source File: FieldDocumentationGeneratorTest.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
@Test
public void testGenerateDocumentationForJacksonSubTypes() throws Exception {
    // given
    ObjectMapper mapper = createMapper();

    mockFieldComment(JsonType1.class, "name", "A name");
    mockFieldComment(JsonType1.class, "type", "A type");
    mockFieldComment(JsonType1.class, "base1", "A base 1");
    mockFieldComment(JsonType1.class, "base2", "A base 2");
    mockFieldComment(JsonType1.class, "base3", "A base 3");
    mockFieldComment(JsonType1.class, "base4", "A base 4");
    mockFieldComment(JsonType1SubType1.class, "base1Sub1", "A base 1 sub 1");
    mockFieldComment(JsonType1SubType2.class, "base1Sub2", "A base 1 sub 2");
    mockFieldComment(JsonType2.class, "clazz", "A clazz");
    mockFieldComment(JsonType2SubType1.class, "base2Sub1", "A base 2 sub 1");
    mockFieldComment(JsonType2SubType2.class, "base2Sub2", "A base 2 sub 2");
    mockTypeSpecifier(JsonType1SubType1.class, "[S1]");

    FieldDocumentationGenerator generator =
            new FieldDocumentationGenerator(mapper.writer(),
                    mapper.getDeserializationConfig(), javadocReader, constraintReader, typeMapping,
                    SnippetTranslationManager.getDefaultResolver(), null);
    Type type = JsonType1.class;

    // when
    List<ExtendedFieldDescriptor> fieldDescriptions = cast(generator
            .generateDocumentation(type, mapper.getTypeFactory()).values());

    // then
    assertThat(fieldDescriptions.size(), is(14));
    assertThat(fieldDescriptions.get(0),
            is(descriptor("type", "String", "A type", "true")));
    assertThat(fieldDescriptions.get(1),
            is(descriptor("name", "String", "A name", "true")));
    assertThat(fieldDescriptions.get(2),
            is(descriptor("base1", "Array[Object]", "A base 1", "true")));
    assertThat(fieldDescriptions.get(3),
            is(descriptor("base2", "Object", "A base 2", "true")));
    assertThat(fieldDescriptions.get(4),
            is(descriptor("base3", "Array[Object]", "A base 3", "true")));
    assertThat(fieldDescriptions.get(5),
            is(descriptor("base3[].clazz", "String", "A clazz", "true")));
    assertThat(fieldDescriptions.get(6),
            is(descriptor("base3[].base2Sub1", "String", "A base 2 sub 1", "true")));
    assertThat(fieldDescriptions.get(7),
            is(descriptor("base3[].base2Sub2", "String", "A base 2 sub 2", "true")));
    assertThat(fieldDescriptions.get(8),
            is(descriptor("base4", "Object", "A base 4", "true")));
    assertThat(fieldDescriptions.get(9),
            is(descriptor("base4.clazz", "String", "A clazz", "true")));
    assertThat(fieldDescriptions.get(10),
            is(descriptor("base4.base2Sub1", "String", "A base 2 sub 1", "true")));
    assertThat(fieldDescriptions.get(11),
            is(descriptor("base4.base2Sub2", "String", "A base 2 sub 2", "true")));
    assertThat(fieldDescriptions.get(12),
            is(descriptor("base1Sub1", "String", "A base 1 sub 1 [S1]", "true [S1]")));
    assertThat(fieldDescriptions.get(13),
            is(descriptor("base1Sub2", "String", "A base 1 sub 2", "true")));
}
 
Example 15
Source File: HttpRestWb.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static void find(CloseableHttpClient httpclient, WSSearchOptions wsso) throws Exception {

		System.out.println("find");
		//CloseableHttpClient httpclient = HttpClients.createDefault();
		
        HttpPost httppost = new HttpPost(BASE_PATH + "/services/rest/search/find");
        httppost.addHeader(new BasicHeader("Accept", "application/json"));

		//ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
        ObjectMapper mapper = new ObjectMapper();
        ObjectWriter ow = mapper.writer();
		String jsonStr = ow.writeValueAsString(wsso);
		System.out.println(jsonStr);
		
		StringEntity entity = new StringEntity(jsonStr, ContentType.create("application/json", Consts.UTF_8));
		httppost.setEntity(entity);		

		CloseableHttpResponse response = httpclient.execute(httppost);
		
		int code = response.getStatusLine().getStatusCode();
		System.out.println("HTTPstatus code: "+ code);
		
		if (code == HttpStatus.SC_OK) {
		} else {
			//log.warn("status code is invalid: {}", code);
			System.err.println("status code is invalid: "+ code);
			throw new Exception(response.getStatusLine().getReasonPhrase());
		}			
		
		try {
			HttpEntity rent = response.getEntity();
			if (rent != null) {
				String respoBody = EntityUtils.toString(rent, "UTF-8");
				System.out.println(respoBody);
				
				//JSON from String to Object
				//WSSearchResult obj = mapper.readValue(respoBody, WSSearchResult.class);
				//System.out.println(ow.writeValueAsString(obj) );				
			}
		} finally {
			response.close();
		}
	}
 
Example 16
Source File: EnumValueTest.java    From openapi-generator with Apache License 2.0 4 votes vote down vote up
@Test
public void testEnumTest() {
    // test enum value
    EnumTest enumTest = new EnumTest();
    enumTest.setEnumString(EnumTest.EnumStringEnum.LOWER);
    enumTest.setEnumInteger(EnumTest.EnumIntegerEnum.NUMBER_1);
    enumTest.setEnumNumber(EnumTest.EnumNumberEnum.NUMBER_1_DOT_1);

    assertEquals(EnumTest.EnumStringEnum.UPPER.toString(), "UPPER");
    assertEquals(EnumTest.EnumStringEnum.UPPER.getValue(), "UPPER");
    assertEquals(EnumTest.EnumStringEnum.LOWER.toString(), "lower");
    assertEquals(EnumTest.EnumStringEnum.LOWER.getValue(), "lower");

    assertEquals(EnumTest.EnumIntegerEnum.NUMBER_1.toString(), "1");
    assertTrue(EnumTest.EnumIntegerEnum.NUMBER_1.getValue() == 1);
    assertEquals(EnumTest.EnumIntegerEnum.NUMBER_MINUS_1.toString(), "-1");
    assertTrue(EnumTest.EnumIntegerEnum.NUMBER_MINUS_1.getValue() == -1);

    assertEquals(EnumTest.EnumNumberEnum.NUMBER_1_DOT_1.toString(), "1.1");
    assertTrue(EnumTest.EnumNumberEnum.NUMBER_1_DOT_1.getValue() == 1.1);
    assertEquals(EnumTest.EnumNumberEnum.NUMBER_MINUS_1_DOT_2.toString(), "-1.2");
    assertTrue(EnumTest.EnumNumberEnum.NUMBER_MINUS_1_DOT_2.getValue() == -1.2);

    try {
        // test serialization (object => json)
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
        ObjectWriter ow = mapper.writer();
        String json = ow.writeValueAsString(enumTest);
        assertEquals(json, "{\"enum_string\":\"lower\",\"enum_string_required\":null,\"enum_integer\":1,\"enum_number\":1.1,\"outerEnum\":null}");

        // test deserialization (json => object)
        EnumTest fromString = mapper.readValue(json, EnumTest.class);
        assertEquals(fromString.getEnumString().toString(), "lower");
        assertEquals(fromString.getEnumInteger().toString(), "1");
        assertEquals(fromString.getEnumNumber().toString(), "1.1");

    } catch (Exception e) {
        fail("Exception thrown during serialization/deserialzation of JSON: " + e.getMessage());
    }
}
 
Example 17
Source File: ExportMetadata.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void writeToJsonFile(final ExportMetadata instance, final Path metadata) throws IOException {
	ObjectMapper mapper = new ObjectMapper();
	ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter());
	writer.writeValue(metadata.toFile(), instance);
}
 
Example 18
Source File: AsyncTrelloHttpClient2.java    From trello-java-wrapper with Apache License 2.0 4 votes vote down vote up
public AsyncTrelloHttpClient2(AsyncHttpClient asyncHttpClient, ObjectMapper mapper) {
    this(asyncHttpClient, mapper.reader(), mapper.writer());
}
 
Example 19
Source File: FieldDocumentationGeneratorTest.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
@Test
public void testGenerateDocumentationForPlainSubTypes() throws Exception {
    // given
    ObjectMapper mapper = createMapper();

    mockFieldComment(Plain.class, "field", "A field");
    mockFieldComment(Plain.class, "overriddenField", "An overridden field");
    mockFieldComment(PlainX.class, "overriddenField", "Custom 1");
    mockFieldComment(PlainX.class, "x", "A field X");
    mockFieldComment(PlainY.class, "overriddenField", "Custom 2");
    mockFieldComment(PlainY.class, "y", "A field Y");
    mockTypeSpecifier(Plain.class, "");
    mockTypeSpecifier(PlainX.class, "(X)");
    mockTypeSpecifier(PlainY.class, "(Y)");
    mockOptional(Plain.class, "overriddenField", "true");
    mockOptional(PlainX.class, "overriddenField", "false");
    mockOptional(PlainY.class, "overriddenField", "false");
    mockConstraint(Plain.class, "overriddenField", "Size[1]");
    mockConstraint(PlainX.class, "overriddenField", "Size[x]");
    mockConstraint(PlainY.class, "overriddenField", "Size[y]");

    TypeMapping typeMapping = new TypeMapping();
    typeMapping.mapSubtypes(Plain.class, PlainX.class, PlainY.class);

    FieldDocumentationGenerator generator =
            new FieldDocumentationGenerator(mapper.writer(),
                    mapper.getDeserializationConfig(), javadocReader, constraintReader, typeMapping,
                    SnippetTranslationManager.getDefaultResolver(), null);
    Type type = Plain.class;

    // when
    List<ExtendedFieldDescriptor> fieldDescriptions = cast(generator
            .generateDocumentation(type, mapper.getTypeFactory()).values());

    // then
    assertThat(fieldDescriptions.size(), is(4));
    assertThat(fieldDescriptions.get(0),
            is(descriptor("field", "String", "A field", "true")));
    assertThat(fieldDescriptions.get(1),
            is(descriptor("overriddenField", "String",
                    "An overridden field<br>Custom 1 (X)<br>Custom 2 (Y)",
                    Arrays.asList("true", "false (X)", "false (Y)"),
                    "Size[1]", "Size[x] (X)", "Size[y] (Y)")));
    assertThat(fieldDescriptions.get(2),
            is(descriptor("x", "String", "A field X (X)", "true (X)")));
    assertThat(fieldDescriptions.get(3),
            is(descriptor("y", "String", "A field Y (Y)", "true (Y)")));
}
 
Example 20
Source File: RedirectServlet.java    From rdap_bootstrap_server with ISC License 4 votes vote down vote up
public void makeHelp( OutputStream outputStream ) throws IOException
{
    Response response = new Response( null );
    ArrayList<Notice> notices = new ArrayList<Notice>();

    // do statistics
    for ( Statistics.UrlHits stats : Statistics.UrlHits.values() )
    {
        notices.add( makeStatsNotice( stats ) );
    }

    // totals
    Notice notice = new Notice();
    notice.setTitle( "Totals" );
    String[] description = new String[2];
    description[0] = String.format( "Hits   = %5d", statistics.getTotalHits().get() );
    description[1] = String.format( "Misses = %5d", statistics.getTotalMisses().get() );
    notice.setDescription( description );
    notices.add( notice );

    // Modified dates for various bootstrap files, done this way so that
    // Publication dates can be published as well.
    notices.add( createPublicationDateNotice( "Default",
        resourceFiles.getLastModified( BootFiles.DEFAULT.getKey() ),
        defaultBootstrap.getPublication() ) );
    notices.add( createPublicationDateNotice( "As",
        resourceFiles.getLastModified( BootFiles.AS.getKey() ),
        asBootstrap.getPublication() ) );
    notices.add( createPublicationDateNotice( "Domain",
        resourceFiles.getLastModified( BootFiles.DOMAIN.getKey() ),
        domainBootstrap.getPublication() ) );
    notices.add( createPublicationDateNotice( "Entity",
        resourceFiles.getLastModified( BootFiles.ENTITY.getKey() ),
        entityBootstrap.getPublication() ) );
    notices.add( createPublicationDateNotice( "IpV4",
        resourceFiles.getLastModified( BootFiles.V4.getKey() ),
        ipV4Bootstrap.getPublication() ) );
    notices.add( createPublicationDateNotice( "IpV6",
        resourceFiles.getLastModified( BootFiles.V6.getKey() ),
        ipV6Bootstrap.getPublication() ) );

    response.setNotices( notices );

    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion( Include.NON_EMPTY );
    ObjectWriter writer = mapper.writer( new DefaultPrettyPrinter() );
    writer.writeValue( outputStream, response );
}