Giter Club home page Giter Club logo

jackson-util-streaming's Introduction

Utilities for streaming JSON processing:
* DeletingParser - Removes specified subtrees from a JSON tree.
* PatchingGenerator - Replaces or adds specified subtrees in a JSON tree.

DeletingParser example:

        HashMap<String,Object> deletes = new HashMap<String,Object>();
        HashMap<String,Object> adeletes = new HashMap<String,Object>();
        deletes.put("a", adeletes);
        adeletes.put("a", null);
        deletes.put("d", null);

        JsonFactory jf = new JsonFactory();
        JsonParser jp = new DeletingParser(jf.createParser("{\"a\":{\"a\":[1,2,3,{\"b\":false,\"c\":null}],\"b\":1},\"b\":[1,2,3],\"c\":true,\"d\":4}"), deletes);
        jp.nextToken();
        StringWriter sw = new StringWriter();
        JsonGenerator jg = jf.createGenerator(sw);
        jg.copyCurrentStructure(jp);
        jg.flush();
        System.out.println(sw.toString());

should print: {"a":{"b":1},"b":[1,2,3],"c":true}

PatchingGenerator example:
        Map<String,Object> patches = new LinkedHashMap<String,Object>();
        ArrayList<Object> list = new ArrayList<Object>();
        patches.put("d", list);
        list.add(false);
        list.add(null);
        list.add(1);
        patches.put("e", 5);
        Map<String,Object> apatch = new LinkedHashMap<String,Object>();
        patches.put("a", apatch);
        apatch.put("a", 0);
        apatch.put("c", 2);

        JsonFactory jf = new JsonFactory();
        JsonParser jp = jf.createParser("{\"a\":{\"a\":[1,2,3,{\"b\":false,\"c\":null}],\"b\":1},\"b\":[1,2,3],\"c\":true,\"d\":4}");
        StringWriter sw = new StringWriter();
        JsonGenerator jg = new PatchingGenerator(jf.createGenerator(sw), patches);
        jp.nextToken();
        jg.copyCurrentStructure(jp);
        jg.flush();
        System.out.println(sw.toString());

should print: {"a":{"a":0,"b":1,"c":2},"b":[1,2,3],"c":true,"d":[false,null,1],"e":5}

jackson-util-streaming's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.