An open API service indexing awesome lists of open source software.

https://github.com/itzg/jsonschema2pojo-rules-bettermaps

Custom RuleFactory for the jsonschema2pojo facility that identifies additionalProperties that only declare a simple type and generates a Map without an intermediate property POJO.
https://github.com/itzg/jsonschema2pojo-rules-bettermaps

java json-schema maven-plugin

Last synced: about 1 month ago
JSON representation

Custom RuleFactory for the jsonschema2pojo facility that identifies additionalProperties that only declare a simple type and generates a Map without an intermediate property POJO.

Awesome Lists containing this project

README

        

This is a custom `RuleFactory` for the [jsonschema2pojo facility](https://github.com/joelittlejohn/jsonschema2pojo)
that identifies `additionalProperties` that only declare a simple type and generates a
`Map` where `TYPE` is the boxed type of the property, such as `String`, or `Integer`.

To use it with the Maven plugin, add this artifact as a dependency of the plugin and set
the `customRuleFactory` to `me.itzg.jsonschema2pojo.bettermaps.BetterMapsRuleFactory`.

For example,

```xml

org.jsonschema2pojo
jsonschema2pojo-maven-plugin
${jsonschema2pojo.version}

${basedir}/src/main/resources/schema

me.itzg.jsonschema2pojo.bettermaps.BetterMapsRuleFactory




generate





me.itzg
jsonschema2pojo-rules-bettermaps
1.0-SNAPSHOT

```

## Example

Given the following schema,

```json
{
"type":"object",
"properties": {
"foo": {
"type": "string"
},
"bars": {
"type": "object",
"additionalProperties": {
"type":"string"
}
},
"times": {
"type": "object",
"additionalProperties": {
"type":"integer"
}
},
"baz": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
}
}
```

The root class, called `MyClass` in this example, contains direct `Map` fields for `bars` and `times`
without the need to reference or declare additional POJO types. The field `baz` still generates
a POJO that contains fields `key` and `value` since it itself is a complex structure.

```java
public class MyClass {

@JsonProperty("foo")
private String foo;
@JsonProperty("bars")
private Map bars;
@JsonProperty("times")
private Map times;
@JsonProperty("baz")
private Baz baz;
// ...snip
}

public class Baz {

@JsonIgnore
private Map additionalProperties =
new HashMap();
// ...snip
}

public class BazProperty {

@JsonProperty("key")
private String key;
@JsonProperty("value")
private String value;
// ...snip
}
```

The `Baz` and `BazProperty` effectively demonstrate the benefit of this rule factory.