Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions jsonb-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.20</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-prisms</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.avaje.jsonb.generator;

import java.util.List;
import java.util.Optional;

import javax.lang.model.element.Element;

import com.fasterxml.jackson.annotation.JsonAlias;

import io.avaje.jsonb.Json.Alias;
import io.avaje.prism.GeneratePrism;

@GeneratePrism(value = Alias.class, name = "AvajeAliasPrism", superInterfaces = AliasPrism.class)
@GeneratePrism(
value = JsonAlias.class,
name = "JacksonAliasPrism",
superInterfaces = AliasPrism.class)
public interface AliasPrism {


static Optional<AliasPrism> getOptionalOn(Element element) {
return Optional.<AliasPrism>empty()
.or(() -> AvajeAliasPrism.getOptionalOn(element))
.or(() -> JacksonAliasPrism.getOptionalOn(element));
}

List<String> value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.avaje.jsonb.generator;

import javax.lang.model.element.Element;

import com.fasterxml.jackson.annotation.JsonCreator;

import io.avaje.jsonb.Json.Creator;
import io.avaje.prism.GeneratePrism;

@GeneratePrism(
value = Creator.class,
name = "AvajeCreatorPrism",
superInterfaces = CreatorPrism.class)
@GeneratePrism(
value = JsonCreator.class,
name = "JacksonCreatorPrism",
superInterfaces = CreatorPrism.class)
public interface CreatorPrism {

static boolean isPresent(Element element) {
return AvajeCreatorPrism.isPresent(element) || JacksonCreatorPrism.isPresent(element);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.avaje.jsonb.generator;

import java.util.Optional;

import javax.lang.model.element.Element;

import com.fasterxml.jackson.annotation.JsonIgnore;

import io.avaje.jsonb.Json.Ignore;
import io.avaje.prism.GeneratePrism;

@GeneratePrism(value = Ignore.class, name = "AvajeIgnorePrism", superInterfaces = IgnorePrism.class)
@GeneratePrism(
value = JsonIgnore.class,
name = "JacksonIgnorePrism",
superInterfaces = IgnorePrism.class)
public interface IgnorePrism {

static IgnorePrism getInstanceOn(Element element) {
return getOptionalOn(element).orElse(null);
}

static Optional<IgnorePrism> getOptionalOn(Element element) {
return Optional.<IgnorePrism>empty()
.or(() -> AvajeIgnorePrism.getOptionalOn(element))
.or(() -> JacksonIgnorePrism.getOptionalOn(element));
}

default Boolean serialize() {
return false;
}

default Boolean deserialize() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.avaje.jsonb.generator;

import java.util.Optional;

import javax.lang.model.element.Element;

import com.fasterxml.jackson.annotation.JsonProperty;

import io.avaje.jsonb.Json.Property;
import io.avaje.prism.GeneratePrism;

@GeneratePrism(
value = Property.class,
name = "AvajePropertyPrism",
superInterfaces = PropertyPrism.class)
@GeneratePrism(
value = JsonProperty.class,
name = "JacksonPropertyPrism",
superInterfaces = PropertyPrism.class)
public interface PropertyPrism {

static boolean isPresent(Element element) {

return AvajePropertyPrism.isPresent(element) || JacksonPropertyPrism.isPresent(element);
}

static PropertyPrism getInstanceOn(Element element) {
return getOptionalOn(element).orElse(null);
}

static Optional<PropertyPrism> getOptionalOn(Element element) {
return Optional.<PropertyPrism>empty()
.or(() -> AvajePropertyPrism.getOptionalOn(element))
.or(() -> JacksonPropertyPrism.getOptionalOn(element));
}

String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
@GeneratePrism(io.avaje.jsonb.Json.class)
@GeneratePrism(io.avaje.jsonb.Json.Import.class)
@GeneratePrism(io.avaje.jsonb.Json.Import.Imports.class)
@GeneratePrism(io.avaje.jsonb.Json.Alias.class)
@GeneratePrism(io.avaje.jsonb.Json.Creator.class)
@GeneratePrism(io.avaje.jsonb.Json.Ignore.class)
@GeneratePrism(io.avaje.jsonb.Json.Property.class)
@GeneratePrism(io.avaje.jsonb.Json.MixIn.class)
@GeneratePrism(io.avaje.jsonb.Json.Raw.class)
@GeneratePrism(io.avaje.jsonb.Json.SubTypes.class)
@GeneratePrism(io.avaje.jsonb.Json.SubType.class)
@GeneratePrism(io.avaje.jsonb.Json.Unmapped.class)
@GeneratePrism(io.avaje.jsonb.Json.Value.class)
@GeneratePrism(io.avaje.jsonb.Json.Serializer.class)
@GeneratePrism(io.avaje.jsonb.Json.Value.class)
@GeneratePrism(io.avaje.jsonb.spi.MetaData.class)
@GeneratePrism(io.avaje.jsonb.spi.MetaData.JsonFactory.class)
package io.avaje.jsonb.generator;
Expand Down
1 change: 1 addition & 0 deletions jsonb-generator/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module io.avaje.jsonb.generator {

requires java.compiler;
requires static com.fasterxml.jackson.annotation;
requires static io.avaje.json;
requires static io.avaje.jsonb;
requires static io.avaje.prism;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.avaje.jsonb.generator.models.valid.jackson;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import io.avaje.jsonb.Json;

@Json.Import(JacksonExample.class)
public class JacksonExample {

@JsonProperty("id")
private final int id;

@JsonProperty("name")
private String name;

@JsonIgnore private String internalCode;

@JsonCreator
public JacksonExample(
@JsonAlias({"identifier", "userId"}) @JsonProperty("id") int id,
@JsonProperty("name") String name) {
this.id = id;
this.name = name;
this.internalCode = "";
}

public int getId() {
return id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getInternalCode() {
return internalCode;
}

public void setInternalCode(String internalCode) {
this.internalCode = internalCode;
}
}