Skip to content

Commit

Permalink
fix JsonCreator interaction with Property
Browse files Browse the repository at this point in the history
  • Loading branch information
SentryMan committed Jun 20, 2024
1 parent 2c910de commit c96654b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ private void writeAdapter(TypeElement typeElement, BeanReader beanReader) {
if (beanReader.hasJsonAnnotation()) {
logError("Error JsonAdapter due to nonAccessibleField for %s ", beanReader);
}
logNote("Skipped writing JsonAdapter for %s due to non accessible fields", beanReader);
return;
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ void read(TypeElement type) {
for (var param : constructor.getParams()) {
var name = param.name();
var element = param.element();
var matchingField = localFields.stream()
.filter(f -> f.propertyName().equals(name))
.findFirst();
var matchingField =
localFields.stream()
.filter(f -> f.propertyName().equals(name) || f.fieldName().equals(name)|| f.fieldName().equals(name))
.findFirst();
matchingField.ifPresentOrElse(f -> f.readParam(element), () -> readField(element, localFields));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package io.avaje.jsonb.generator.models.valid;

import java.io.IOException;
import java.io.Serializable;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.Temporal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;

import io.avaje.jsonb.Json;

@Json
public final class PropertyCreator {

private final transient String[] arguments;

private final transient List<Consumer<?>> hooks;

@Json.Property("uid")
private final String identifier;

@Json.Property("stp")
private final Instant startup;

@Json.Property("cfg")
private final Properties configuration;

@Json.Property("ins")
private final Set<PropertyCreator> instances;

@Json.Creator
public PropertyCreator(
String identifier,
Instant startup,
Properties configuration,
Set<PropertyCreator> instances) {
this.arguments = null;
this.hooks = null;

this.identifier = identifier;
this.startup = startup;
this.configuration = configuration;
this.instances = null;
}

public PropertyCreator(String[] arguments, Instant startup) throws IOException {
this.arguments = arguments != null ? arguments : new String[0];
this.hooks = new ArrayList<>();

this.identifier = Instant.now().toEpochMilli() + "-" + UUID.randomUUID();
this.startup = startup;

this.configuration = new Properties();
this.configuration.putAll(System.getenv());
this.configuration.putAll(System.getProperties());

this.instances = new HashSet<>();
}

public String[] arguments() {
return arguments;
}

public String identifier() {
return this.identifier;
}

public Instant startup() {
return this.startup;
}

public Properties configuration() {
return this.configuration;
}

public Set<PropertyCreator> instances() {
return this.instances;
}

@Json.Property("upt")
public Duration uptime() {
return Duration.ofMillis(1);
}
}

0 comments on commit c96654b

Please sign in to comment.