|
17 | 17 | import com.dylibso.chicory.wasm.types.ValType; |
18 | 18 | import com.dylibso.chicory.wasm.types.ValueType; |
19 | 19 | import com.fasterxml.jackson.core.JsonProcessingException; |
| 20 | +import com.fasterxml.jackson.databind.BeanDescription; |
| 21 | +import com.fasterxml.jackson.databind.DeserializationConfig; |
| 22 | +import com.fasterxml.jackson.databind.JsonDeserializer; |
20 | 23 | import com.fasterxml.jackson.databind.JsonMappingException; |
21 | 24 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 25 | +import com.fasterxml.jackson.databind.deser.BeanDeserializerBuilder; |
| 26 | +import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier; |
| 27 | +import com.fasterxml.jackson.databind.module.SimpleModule; |
22 | 28 | import com.google.protobuf.Struct; |
23 | 29 | import dev.openfeature.contrib.providers.flagd.FlagdOptions; |
24 | 30 | import dev.openfeature.contrib.providers.flagd.resolver.Resolver; |
@@ -64,6 +70,15 @@ public class InProcessWasmResolver implements Resolver { |
64 | 70 |
|
65 | 71 | private static final Function<Instance, Machine> MACHINE_FUNCTION; |
66 | 72 | private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
| 73 | + |
| 74 | + { |
| 75 | + |
| 76 | + // Register this module with your ObjectMapper |
| 77 | + SimpleModule module = new SimpleModule(); |
| 78 | + module.addDeserializer(ImmutableMetadata.class, new ImmutableMetadataDeserializer()); |
| 79 | + OBJECT_MAPPER.registerModule(module); |
| 80 | + } |
| 81 | + |
67 | 82 | private final Consumer<FlagdProviderEvent> onConnectionEvent; |
68 | 83 | private final String scope; |
69 | 84 | private final QueueSource connector; |
@@ -294,7 +309,8 @@ private <T> ProviderEvaluation<T> resolve(Class<T> type, String key, EvaluationC |
294 | 309 | dealloc.apply(flagPtr, flagBytes.length); |
295 | 310 | dealloc.apply(ctxPtr, ctxBytes.length); |
296 | 311 | try { |
297 | | - return OBJECT_MAPPER.readValue(result, ProviderEvaluation.class); |
| 312 | + ProviderEvaluation providerEvaluation = OBJECT_MAPPER.readValue(result, ProviderEvaluation.class); |
| 313 | + return providerEvaluation; |
298 | 314 | } catch (JsonProcessingException e) { |
299 | 315 | throw new RuntimeException(e); |
300 | 316 | } |
@@ -652,4 +668,19 @@ private static HostFunction createWbindgenError() { |
652 | 668 | ); |
653 | 669 | } |
654 | 670 |
|
| 671 | + // Implement a custom deserializer for ImmutableMetadata |
| 672 | + public class ImmutableMetadataDeserializer extends JsonDeserializer<ImmutableMetadata> { |
| 673 | + @Override |
| 674 | + public ImmutableMetadata deserialize(com.fasterxml.jackson.core.JsonParser p, |
| 675 | + com.fasterxml.jackson.databind.DeserializationContext ctxt) |
| 676 | + throws IOException { |
| 677 | + // Deserialize into a Map or DTO, then use the builder |
| 678 | + Map<String, Object> map = p.readValueAs(Map.class); |
| 679 | + ImmutableMetadata.ImmutableMetadataBuilder builder = ImmutableMetadata.builder(); |
| 680 | + for (Map.Entry<String, Object> entry : map.entrySet()) { |
| 681 | + builder.addString(entry.getKey(), entry.getValue().toString()); |
| 682 | + } |
| 683 | + return builder.build(); |
| 684 | + } |
| 685 | + } |
655 | 686 | } |
0 commit comments