jason

Jason - elastic JSON serializer based on GSON.

Лицензия

Лицензия

Категории

Категории

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

Группа

org.jasonjson
Идентификатор

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

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

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

0.1.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

jason
Jason - elastic JSON serializer based on GSON.
Система контроля версий

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

https://github.com/adamdubiel/jason

Скачать jason

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

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

Зависимости

test (6)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.11
org.mockito : mockito-all jar 1.9.5
com.googlecode.catch-exception : catch-exception jar 1.0.4
org.easytesting : fest-assert-core jar 2.0M10
com.jayway.jsonpath : json-path jar 0.8.1
com.jayway.jsonpath : json-path-assert jar 0.8.1

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

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

Jason


Jason is an elastic JSON serializer/deserializer based on Google Gson 2.2.4 code. For more on Gson visit Google Code page.

Why?

Gson is a great, performant tool with great architecture. There is one thing missing though - runtime filtering. Filters (or excluders) need to be defined up front, before gson object is built. Jason aims at bringing runtime excluders passed on serialize/deserialize method call.

This project is here to show that it is possible. I will try to contact Gson authors to merge code.

What's new?

  • runtime transformations
  • serialization using getters

How to use it?

Runtime transformation

To define runtime filter that will allow only name fields:

// given
RuntimeFilters filters = new RuntimeFiltersBuilder().including("name").build();

DummyClass dummy = DummyClassBuilder.dummyClass().withName("dummy").build();

// when
Strign json = gson.toJson(dummy, filters);

// then
assertThat(json).isEqualTo("{name: \"dummy\"}");

Runtime filter that will restrict fields only on chosen class:

// given
RuntimeFilters filters = new RuntimeFiltersBuilder().including(DummyClass.class, "name", "id").build();

DummyClass dummy = DummyClassBuilder.dummyClass().withName("dummy").withId(42).build();
Aggregate aggregate = AggregateBuilder.aggregate().withName("aggregate").contains(dummy);

// when
Strign json = gson.toJson(aggregate, filters);

// then
assertThat(json).isEqualTo("{name: \"aggregate\" content: [{ name: \"dummy\", id: 42}] }");

Attribute filters

Attribute filters allow to perform global and local exclusions based on field name only. Runtime transformations are dynamic and should not rely on complex information about field (like annotations). Any complex exclusions should be handled via ExclusionStrategy.

Attribute filtering precedence:

  • allow all by default
  • global exclusion can be overriden only by class level include
  • include on class level overrides global includes
  • exclude on class level adds up to global excludes

Serialization using getters

By default getter serialization can be turned on using @JasonAccess(strategy = AccessStrategyType.PROPERTY) annotation on class level. You can define own access strategy by providing own implementation of AccessStrategy.

Warning! There is no support for deserialization. Classes which are serialized using getters can't be deserialized!

Compatibility

The only thing that needs to be changed after moving to Jason is ExclusionStrategy implementations signature. Instead of FieldAttributes interface skipField method now accepts Attribute, which can be either field or property (getter). Attribute interface offers same possibilities as FieldAttribute.

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

Версия
0.1.1
0.1.0