jsonschema2pojo Android Data Binding

jsonschema2pojo extension to generate Android Data Binding specific POJOs

Лицензия

Лицензия

Категории

Категории

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

Группа

io.github.hectorbst
Идентификатор

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

jsonschema2pojo-androidx-databinding
Последняя версия

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

0.3.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

jsonschema2pojo Android Data Binding
jsonschema2pojo extension to generate Android Data Binding specific POJOs
Ссылка на сайт

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

https://github.com/hectorbst/jsonschema2pojo-androidx-databinding
Система контроля версий

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

https://github.com/hectorbst/jsonschema2pojo-androidx-databinding

Скачать jsonschema2pojo-androidx-databinding

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

<!-- https://jarcasting.com/artifacts/io.github.hectorbst/jsonschema2pojo-androidx-databinding/ -->
<dependency>
    <groupId>io.github.hectorbst</groupId>
    <artifactId>jsonschema2pojo-androidx-databinding</artifactId>
    <version>0.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.hectorbst/jsonschema2pojo-androidx-databinding/
implementation 'io.github.hectorbst:jsonschema2pojo-androidx-databinding:0.3.0'
// https://jarcasting.com/artifacts/io.github.hectorbst/jsonschema2pojo-androidx-databinding/
implementation ("io.github.hectorbst:jsonschema2pojo-androidx-databinding:0.3.0")
'io.github.hectorbst:jsonschema2pojo-androidx-databinding:jar:0.3.0'
<dependency org="io.github.hectorbst" name="jsonschema2pojo-androidx-databinding" rev="0.3.0">
  <artifact name="jsonschema2pojo-androidx-databinding" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.hectorbst', module='jsonschema2pojo-androidx-databinding', version='0.3.0')
)
libraryDependencies += "io.github.hectorbst" % "jsonschema2pojo-androidx-databinding" % "0.3.0"
[io.github.hectorbst/jsonschema2pojo-androidx-databinding "0.3.0"]

Зависимости

provided (1)

Идентификатор библиотеки Тип Версия
org.jsonschema2pojo : jsonschema2pojo-core jar 1.0.2

test (5)

Идентификатор библиотеки Тип Версия
org.junit.jupiter : junit-jupiter-api jar
org.junit.jupiter : junit-jupiter-engine jar
org.junit.platform : junit-platform-runner jar
org.junit.jupiter : junit-jupiter-params jar
org.assertj : assertj-core jar 3.17.2

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

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

Build Coverage Violations Maven Central License

jsonschema2pojo-androidx-databinding

This project is a jsonschema2pojo extension dedicated to observable entities generation for Android Data Binding.

Features

Observable objects

This extension generate observable data objects as explained here.

E.g., this schema:

{
	"title": "Sample entity",
	"type": "object",
	"properties": {
		"field": {
			"title": "A field",
			"type": "string"
		}
	}
}

Will produce:

public class Entity extends BaseObservable {

	private String field;

	@Bindable
	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
		notifyPropertyChanged(BR.field);
	}
}

Collections and maps

Collection type fields become ObservableList and Map type fields become ObservableMap.

E.g., this schema:

{
	"title": "Sample entity",
	"type": "object",
	"properties": {
		"field": {
			"title": "A list",
			"type": "array",
			"items": {
				"type": "string"
			}
		}
	}
}

Will produce:

public class Entity extends BaseObservable {

	private ObservableList<String> field;

	@Bindable
	public ObservableList<String> getField() {
		return field;
	}

	public void setField(ObservableList<String> field) {
		this.field = field;
		notifyPropertyChanged(BR.field);
	}
}

Disable observability for specific fields or classes

It is possible to exclude fields or classes from observability if they are not concerned by Data Binding, setting the JSON property x-adb-observable to false at property or schema level (if missing or null the value is true).

E.g., this schema:

{
	"title": "Sample entity",
	"type": "object",
	"properties": {
		"field": {
			"title": "A string",
			"type": "string"
		},
		"excludedField": {
			"title": "A string",
			"type": "string",
			"x-adb-observable": false
		}
	}
}

Will produce:

public class Entity extends BaseObservable {

	private String field;

	private String excludedField;

	@Bindable
	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
		notifyPropertyChanged(BR.field);
	}

	public String getExcludedField() {
		return field;
	}

	public void setExcludedField(String field) {
		this.field = field;
	}
}

If x-adb-observable is set to false for an object, this value will be propagated to all properties.

Gradle configuration

Here is an example of how the extension can be added to the jsonschema2pojo Gradle plugin in a Android project.

...

buildscript {
	...
	dependencies {
		...
		//jsonschema2pojo dependency
		classpath "org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:${jsonschema2pojoVersion}"
		//Extension dependency
		classpath "io.github.hectorbst:jsonschema2pojo-androidx-databinding:${jsonschema2pojoDataBindingVersion}"
	}
}

apply plugin: 'com.android.library'
apply plugin: 'jsonschema2pojo'

android {
	...

	buildFeatures {
		//Enable data binding
		dataBinding = true
	}
}

...

jsonSchema2Pojo {
	...
	//Extension RuleFactory
	customRuleFactory = 'io.github.hectorbst.jsonschema2pojo.androidx.databinding.AndroidDataBindingRuleFactory'
}

A more complete example testable in an Android application is available here.

License

This project is released under version 2.0 of the Apache License.

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

Версия
0.3.0
0.2.0
0.1.0
0.0.1