Skip to content

Commit

Permalink
fix JsonAnySetter
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Sep 27, 2024
1 parent 6a5861f commit d3c45e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.TreeMap;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Envelope;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Metadata associated with a tile archive.
Expand Down Expand Up @@ -49,6 +47,7 @@ public record TileArchiveMetadata(
@JsonSerialize(using = TileArchiveMetadataDeSer.MetadataJsonSerializer.class)
@JsonDeserialize(using = TileArchiveMetadataDeSer.MetadataJsonDeserializer.class) TileArchiveMetadataJson json,
@JsonAnyGetter
@JsonAnySetter
@JsonDeserialize(using = TileArchiveMetadataDeSer.EmptyMapIfNullDeserializer.class) Map<String, String> others,
@JsonProperty(COMPRESSION_KEY) TileCompression tileCompression
) {
Expand All @@ -71,8 +70,6 @@ public record TileArchiveMetadata(

public static final String MVT_FORMAT = "pbf";

private static final Logger LOGGER = LoggerFactory.getLogger(TileArchiveMetadata.class);

public TileArchiveMetadata(Profile profile, PlanetilerConfig config) {
this(profile, config, null);
}
Expand All @@ -94,7 +91,7 @@ public TileArchiveMetadata(Profile profile, PlanetilerConfig config, List<LayerA
config.minzoom(),
config.maxzoom(),
vectorLayers == null ? null : new TileArchiveMetadataJson(vectorLayers),
mergeMaps(mapWithBuildInfo(),profile.extraArchiveMetadata()),
mergeMaps(mapWithBuildInfo(), profile.extraArchiveMetadata()),
config.tileCompression()
);
}
Expand Down Expand Up @@ -170,23 +167,12 @@ public TileArchiveMetadata withJson(TileArchiveMetadataJson json) {
maxzoom, json, others, tileCompression);
}

/*
* few workarounds to make collect unknown fields to others work,
* because @JsonAnySetter does not yet work on constructor/creator arguments
* https://github.com/FasterXML/jackson-databind/issues/3439
*/

private static Map<String,String> mergeMaps(Map<String,String> m1, Map<String,String> m2) {
private static Map<String, String> mergeMaps(Map<String, String> m1, Map<String, String> m2) {
var result = new TreeMap<>(m1);
result.putAll(m2);
return result;
}

@JsonAnySetter
private void putUnknownFieldsToOthers(String name, String value) {
others.put(name, value);
}


public record TileArchiveMetadataJson(
@JsonProperty(VECTOR_LAYERS_KEY) List<LayerAttrStats.VectorLayer> vectorLayers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,14 @@ public static List<Entry> directoryFromBytes(byte[] bytes) {
*/
public record JsonMetadata(
@JsonProperty("vector_layers") List<LayerAttrStats.VectorLayer> vectorLayers,
@JsonAnyGetter Map<String, String> otherMetadata
@JsonAnySetter @JsonAnyGetter Map<String, String> otherMetadata
) {

@JsonCreator
public JsonMetadata(@JsonProperty("vector_layers") List<LayerAttrStats.VectorLayer> vectorLayers) {
this(vectorLayers, new HashMap<>());
}

@JsonAnySetter
private void setExtraMetadata(String key, String val) {
otherMetadata.put(key, val);
}

public byte[] toBytes() {

try {
Expand Down

0 comments on commit d3c45e9

Please sign in to comment.