Jackson Gson json.simple Part 2

Source: Internet
Author: User

This blog introduces Jackson's features and how to use it

Jackson supports three ways to use

    • Streaming API (Streaming API Incremental parsing/generation)
      • Jsonparse reads, Jsongenerator writes
      • Efficient
      • Similar to the use of Part 1 JSON, it is not useful
    • Tree-shaped model
      • Objectmapper used to build and use with Jsonnode.
    • Data binding
      • JSON and Pojo convert each other
      • Simple data conversion Simple object refers to the map in Java, list, etc.
      • Full Data Conversion Custom JavaBean

    

User's perspective to evaluate these three methods of use

    • Flow mode is the most efficient, fast, low memory consumption
    • Data binding is the most convenient
    • The most flexible tree-shaped model

Example:

Data binding examples

Json Javabean

User user = new user (); Javabeanobjectmapper mapper = new Objectmapper () Mapper.writevalue (New File ("/users/sangs/downloads/json.txt"), user); Write to File System.out.println (mapper.writevalueasstring (user));

Json-Javabean

Objectmapper mapper = new Objectmapper (); User user = Mapper.readvalue (new File ("/users/sangs/downloads/json.txt"), User.class); SYSTEM.OUT.PRINTLN (user);

The Javabean and JSON transformations are fairly simple and look intuitive, requiring only one converter objectmapper

Conversion of raw data to JSON

If we have the raw data, we want to be able to use the data directly into JSON, this JSON can be converted to JavaBean

Map<String, Object>UserData = new HashMap<String, Object>(); Map<String, String>namestruct = new HashMap<String, String>( ); Namestruct.put ("First", "Joe"), Namestruct.put ("Last", "Sixpack"), Userdata.put ("name", namestruct); Userdata.put ("Gender", "MALE"), Userdata.put ("verified", Boolean.false), Userdata.put ("Userimage", "rm9vymfyiq=="); Mapper.writevalue (New File ("User-modified.json"), userData);

Jackson Gson json.simple Part 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.