Skip to content

Commit b8ccfa5

Browse files
committed
fix: add missing property names on creator methods
1 parent 9d5f71f commit b8ccfa5

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

metadata/src/main/java/net/laprun/sustainability/power/SensorMetadata.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public SensorMetadata(List<ComponentMetadata> components, String documentation)
7676
}
7777

7878
@JsonCreator
79-
SensorMetadata(Map<String, ComponentMetadata> components, String documentation) {
79+
SensorMetadata(@JsonProperty("metadata") Map<String, ComponentMetadata> components,
80+
@JsonProperty("documentation") String documentation) {
8081
this.components = components;
8182
this.documentation = documentation;
8283
}
@@ -228,7 +229,10 @@ public record ComponentMetadata(String name, int index, String description, bool
228229
}
229230
}
230231

231-
public ComponentMetadata(String name, int index, String description, boolean isAttributed, String unitSymbol) {
232+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
233+
public ComponentMetadata(@JsonProperty("name") String name, @JsonProperty("index") int index,
234+
@JsonProperty("description") String description,
235+
@JsonProperty("isAttributed") boolean isAttributed, @JsonProperty("unit") String unitSymbol) {
232236
this(name, index, description, isAttributed, SensorUnit.of(unitSymbol));
233237
}
234238
}

metadata/src/main/java/net/laprun/sustainability/power/SensorUnit.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ public SensorUnit(String symbol, SensorUnit base, double factor) {
3333
this.factor = factor < 0 ? 1 : factor;
3434
}
3535

36-
@JsonCreator
36+
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
3737
public static SensorUnit of(String symbol) {
38+
symbol = Objects.requireNonNull(symbol, "Unit symbol cannot be null").trim();
39+
if (symbol.isBlank()) {
40+
throw new IllegalArgumentException("Unit symbol cannot be blank");
41+
}
42+
3843
var unit = baseUnits.get(symbol);
3944
if (unit != null) {
4045
return unit;
@@ -45,11 +50,6 @@ public static SensorUnit of(String symbol) {
4550
return unit;
4651
}
4752

48-
symbol = Objects.requireNonNull(symbol, "Unit symbol cannot be null").trim();
49-
if (symbol.isBlank()) {
50-
throw new IllegalArgumentException("Unit symbol cannot be blank");
51-
}
52-
5353
if (symbol.length() == 1) {
5454
// assume base unit
5555
return baseUnitFor(symbol);

0 commit comments

Comments
 (0)