Jackson Interceptor Module

Jackson 2.x module for intercepting and manipulating raw JSON before deserialization and after serialization.

Лицензия

Лицензия

Категории

Категории

JSON Данные Jackson
Группа

Группа

com.github.jonpeterson
Идентификатор

Идентификатор

jackson-module-json-interceptor
Последняя версия

Последняя версия

1.0.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

Jackson Interceptor Module
Jackson 2.x module for intercepting and manipulating raw JSON before deserialization and after serialization.
Ссылка на сайт

Ссылка на сайт

https://github.com/jonpeterson/jackson-module-json-interceptor
Система контроля версий

Система контроля версий

https://github.com/jonpeterson/jackson-module-json-interceptor

Скачать jackson-module-json-interceptor

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.github.jonpeterson/jackson-module-json-interceptor/ -->
<dependency>
    <groupId>com.github.jonpeterson</groupId>
    <artifactId>jackson-module-json-interceptor</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.jonpeterson/jackson-module-json-interceptor/
implementation 'com.github.jonpeterson:jackson-module-json-interceptor:1.0.0'
// https://jarcasting.com/artifacts/com.github.jonpeterson/jackson-module-json-interceptor/
implementation ("com.github.jonpeterson:jackson-module-json-interceptor:1.0.0")
'com.github.jonpeterson:jackson-module-json-interceptor:jar:1.0.0'
<dependency org="com.github.jonpeterson" name="jackson-module-json-interceptor" rev="1.0.0">
  <artifact name="jackson-module-json-interceptor" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.jonpeterson', module='jackson-module-json-interceptor', version='1.0.0')
)
libraryDependencies += "com.github.jonpeterson" % "jackson-module-json-interceptor" % "1.0.0"
[com.github.jonpeterson/jackson-module-json-interceptor "1.0.0"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
com.fasterxml.jackson.core : jackson-databind jar [2.2.0,)
org.slf4j : slf4j-api jar 1.7.12

test (3)

Идентификатор библиотеки Тип Версия
org.codehaus.groovy : groovy-all jar 2.4.5
org.slf4j : slf4j-simple jar 1.7.12
org.spockframework : spock-core jar 1.0-groovy-2.4

Модули Проекта

Данный проект не имеет модулей.

Jackson JSON Interceptor Module

Jackson 2.x module for intercepting and manipulating raw JSON before deserialization and after serialization.

Compatibility

Compiled for Java 6 and tested with Jackson 2.2 - 2.8.

Getting Started with Gradle

dependencies {
    compile 'com.github.jonpeterson:jackson-module-json-interceptor:1.0.0'
}

Getting Started with Maven

<dependency>
    <groupId>com.github.jonpeterson</groupId>
    <artifactId>jackson-module-json-interceptor</artifactId>
    <version>1.0.0</version>
</dependency>

Example

Define the POJO models

class CarsByType {
    String type
    List<Car> data
}
@JsonInterceptors(beforeDeserialization = CarDeserializationInterceptor)
class Car {
    String make
    String model
    int year
}

Define the JSON interceptor

class CarDeserializationInterceptor implements JsonInterceptor {

    @Override
    JsonNode intercept(JsonNode node, JsonNodeFactory nodeFactory) {
        if(node.isTextual()) {
            def parts = node.asText().split(':')

            def objectNode = nodeFactory.objectNode()
            objectNode.put('make', parts[0])
            objectNode.put('model', parts[1])
            objectNode.put('year', parts[2] as int)
            node = objectNode
        }

        return node
    }
}

Test the interceptor

// create the ObjectMapper and load the JSON Interceptor Module
def mapper = new ObjectMapper().registerModule(new JsonInterceptorModule())

// deserialize the data
def cars = mapper.readValue(

    // note that Honda Civic is expressed in a packed string and Toyota Camry is expressed in an exploded object
    '''{
      |  "type": "sedans",
      |  "data": [
      |    "Honda:Civic:2016",
      |    {
      |      "make":"Toyota",
      |      "model":"Camry",
      |      "year":2017
      |    }
      |  ]
      |}'''.stripMargin(),

    // class to deserialize as
    CarsByType
)

// serialize and compare
assert mapper.writeValueAsString(cars) == '{"type":"sedans","data":[{"make":"Honda","model":"Civic","year":2016},{"make":"Toyota","model":"Camry","year":2017}]}'

See other test cases under src/test/groovy.

JavaDoc

Версии библиотеки

Версия
1.0.0