IntelliJ IDEA plugin for mapping Java class to JSON/AVRO/GraphQL.
APACHE-2.0 License
Intellij IDEA plugin for mapping Java or Kotlin Classes to format like JSON/AVRO/GraphQL/etc.
Plugin allow mapping Java or Kotlin Classes to different formats, this section describes information about supported formats and their options.
All format examples will be showed according to this class as example. Keep in mind that mapping is based on class fields, not getters\setters.
public class User {
private class Credential {
private String id;
private long issued;
}
private UUID id;
private String name;
private List<String> roles;
private Credential credential;
}
Supports also Kotlin classes:
data class ExampleData(val surname: String, val number: Int, val simple: ExampleSimple)
class ExampleSimple {
var en: ExampleEnum? = null
var name: String? = null
var data: ExampleData? = null
var surnames: List<String>? = null
var numbers: Map<String, Int>? = null
var names: Set<String>? = null
}
Plugin uses DummyMaker library for generating classes and then converting to JSON format.
Allow mapping class as JSON example with fields filled with random values as if class example was serialized to JSON format.
{
"id" : "76fbb591-8e95-4df7-94ad-5d0606709141",
"name" : "Alan",
"roles" : [ "herbalist", "recycling-officer", "exploration-geologist" ],
"credential" : {
"id" : "a7ec6315-4292-454c-ac69-e61a7a36e07d",
"issued" : 1565743683
}
}
Also allow mapping class as array of JSONs.
You can specify number of entries to generate in array.
[
{
"id": "526686d0-8d84-4b85-a751-77fa7a157a69",
"name": "Rachel",
"roles": [ "fitness-centre-manager", "plant-breeder", "television-production-assistant" ],
"credential": {
"id": "94f349c9-405a-4921-8dbf-8abfacc28cf1",
"issued": 1548018277
}
}
]
Annotations from Jackson are supported when serializing to JSON, but keep in mind that only fields used for serialization, not getters.
However, Jackson annotations from respected fields getters will be applied during serialization if found, but such behavior is not guarantied to be always correct.
Example for User class:
public class User {
private UUID id;
@JsonProperty(value = "firstName")
private String name;
private String surname;
@JsonIgnore
private List<String> roles;
@JsonIgnore
public String getSurname() {
return surname;
}
}
Mapping User class as JSON will result in (most of Jackson annotations and their parameters are supported):
{
"id": "975e80ed-b95d-46b2-9338-519ff7083dd3",
"firstName": "Alfred"
}
Allow mapping class as JSON Schema, 3 different drafts are available:
Mapping is under:
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"properties": {
"credential": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"issued": {
"type": "integer"
}
}
},
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"roles": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
Allow mapping class as AVRO Schema for version 1.9.2
There is option for two different AVRO Schema builders like:
Mapping is under:
{
"type" : "record",
"name" : "User",
"namespace" : "io.goodforgod.dummymapper",
"fields" : [ {
"name" : "id",
"type" : {
"type" : "record",
"name" : "UUID",
"namespace" : "java.util",
"fields" : [ ]
}
}, {
"name" : "name",
"type" : "string"
}, {
"name" : "roles",
"type" : {
"type" : "array",
"items" : "string",
"java-class" : "java.util.List"
}
}, {
"name" : "credential",
"type" : {
"type" : "record",
"name" : "Credential",
"fields" : [ {
"name" : "id",
"type" : "string"
}, {
"name" : "issued",
"type" : "long"
} ]
}
} ]
}
Jackson annotations are supported when serializing to AVRO Schema, but keep in mind that only fields used for serialization, not getters.
Most of Jackson annotations and their parameters are supported.
Example on how to mark field as required (Option Required By Default apply such transformation for all fields if selected):
public class User {
@JsonProperty(required = true)
private UUID id;
private String name;
private String surname;
}
Annotations from Apache Avro library supported when serializing to AVRO Schema.
Allow mapping class as GraphQL query with version v14
Mapping is under:
schema {
query: Query
}
type Credential {
id: String
issued: Long!
}
#Query root
type Query {
credential: Credential
id: UUID
name: String
roles: [String]
}
#Long type
scalar Long
#Unrepresentable type
scalar UNREPRESENTABLE
#UUID String
scalar UUID
Annotations from GraphQL SPQR library supported when serializing to GraphQL.
There some limitations for plugin when mapping classes:
This project licensed under the Apache 2.0 - see the LICENSE file for details.