Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectMapper


  private static final Logger log = LoggerFactory.getLogger(Marshaller.class);

  final ObjectMapper jsonMapper = buildJsonMapper();

  private ObjectMapper buildJsonMapper() {
    ObjectMapper mapper = new ObjectMapper();
    return mapper;
  }
View Full Code Here


  // return stringWriter.toString();
  // }
  //

  public String marshal(T object, boolean formatted) throws JsonProcessingException, IOException {
    ObjectMapper mapper = JsonHelper.buildObjectMapper(null, formatted);

    return mapper.writeValueAsString(object);
  }
View Full Code Here

    return json;
  }

  public static ObjectMapper buildObjectMapper(TypeFactory typeFactory, boolean formatted) {
    ObjectMapper mapper = new ObjectMapper();

    if (typeFactory == null) {
      typeFactory = TypeFactory.defaultInstance();
    }

    if (formatted) {
      mapper.enable(SerializationFeature.INDENT_OUTPUT);
    }

    // Favor JAXB annotations
    AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(typeFactory);
    AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
    AnnotationIntrospector introspector = new AnnotationIntrospectorPair(jaxbIntrospector, jacksonIntrospector);
    mapper.setAnnotationIntrospector(introspector);

    return mapper;

  }
View Full Code Here

  public ModelHandler(OptiqConnection connection, String uri)
    throws IOException {
    super();
    this.connection = connection;
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
    mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
    JsonRoot root;
    if (uri.startsWith("inline:")) {
      root = mapper.readValue(
          uri.substring("inline:".length()), JsonRoot.class);
    } else {
      root = mapper.readValue(new File(uri), JsonRoot.class);
    }
    visit(root);
  }
View Full Code Here

public class LoadAllCards
{
  public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException
  {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    @SuppressWarnings("unchecked")
    List<MTGCard> allCards = getAllCards((Map<String, MTGSet>)mapper.readValue(new File("AllSets.json"), new TypeReference<Map<String, MTGSet>>()  {}));
   
    System.out.println("Number of cards: " + allCards.size());
  }
View Full Code Here

  protected void doParse(final Element element, final BeanDefinitionBuilder bean) {
    final String objectMapper = element.getAttribute("objectMapper");
    if (StringUtils.hasText(objectMapper)) {
      bean.addPropertyReference("objectMapper", objectMapper);
    } else {
      bean.addPropertyValue("objectMapper", new ObjectMapper());
    }
  }
View Full Code Here

  }

  @Override
  public void afterPropertiesSet() {
    if (objectMapper == null) {
      objectMapper = new ObjectMapper();
    }
  }
View Full Code Here

    final Map<Integer, FoodmartQuery> queries =
        new LinkedHashMap<Integer, FoodmartQuery>();

    private FoodMartQuerySet() throws IOException {
      final ObjectMapper mapper = new ObjectMapper();
      mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
      mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);

      final InputStream inputStream = new FoodMartQuery().getQueries();
      FoodmartRoot root = mapper.readValue(inputStream, FoodmartRoot.class);
      for (FoodmartQuery query : root.queries) {
        queries.put(query.id, query);
      }
    }
View Full Code Here

/**
* Unit test for data models.
*/
public class ModelTest {
  private ObjectMapper mapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
    mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
    return mapper;
  }
View Full Code Here

    return mapper;
  }

  /** Reads a simple schema from a string into objects. */
  @Test public void testRead() throws IOException {
    final ObjectMapper mapper = mapper();
    JsonRoot root = mapper.readValue(
        "{\n"
        + "  version: '1.0',\n"
        + "   schemas: [\n"
        + "     {\n"
        + "       name: 'FoodMart',\n"
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.databind.ObjectMapper

Copyright © 2018 www.massapicom. 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.