Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectMapper.constructType()


    resp.setContentType("application/json");
    ObjectMapper om = new ObjectMapper();
    try
    {
      ObjectWriter writer = om.writer().withType(om.constructType(getClass().getMethod("prototype").getGenericReturnType()));
      writer.writeValue(resp.getOutputStream(), Lists.newArrayList(one, two, three));
    }
    catch (Exception e)
    {
      throw new ServletException(e);
View Full Code Here


    public void testJsonValueAnnotation() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
        mapper.acceptJsonFormatVisitor(mapper.constructType(Leaf.class), visitor);
        JsonSchema schemaExp = visitor.finalSchema();
        assertNotNull(schemaExp);
       
        visitor = new SchemaFactoryWrapper();
        mapper.acceptJsonFormatVisitor(mapper.constructType(ContainerWithAsValue.class), visitor);
View Full Code Here

        mapper.acceptJsonFormatVisitor(mapper.constructType(Leaf.class), visitor);
        JsonSchema schemaExp = visitor.finalSchema();
        assertNotNull(schemaExp);
       
        visitor = new SchemaFactoryWrapper();
        mapper.acceptJsonFormatVisitor(mapper.constructType(ContainerWithAsValue.class), visitor);
        JsonSchema schemaAct = visitor.finalSchema();
        assertNotNull(schemaAct);

        // these are minimal checks:
        assertEquals(schemaExp.getType(), schemaAct.getType());
View Full Code Here

    public void testJsonValueForCollection() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
        mapper.acceptJsonFormatVisitor(mapper.constructType(Issue34Bean.class), visitor);
        JsonSchema schema = visitor.finalSchema();
        assertNotNull(schema);
       
        String schemaStr = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema);
        assertNotNull(schemaStr);
View Full Code Here

            URL schemaLocation = schemaLookup.getSchemaURL(schemaAnnotation.value());
            JsonSchema jsonSchema = cache.getSchema(schemaLocation);
            JsonNode jsonNode = mapper.readTree(jp);
            List<ErrorMessage> validationErrors = jsonSchema.validate(jsonNode);
            if (validationErrors.isEmpty()) {
                return mapper.reader().withType(mapper.constructType(genericType)).readValue(jsonNode);
            }

            throw new WebApplicationException(generateErrorMessage(validationErrors));
        } else {
            return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.