-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Deserialization of InstanceEvents #1348
Comments
Could you please elaborate a bit on your customizing and why you need to deserialize the InstanceEvents using jackson? |
Because the memory currently used for InstanceEvents storage, spring boot admin will be lost after restart, so I use rocksdb to store. Use jackson for serialization. |
Currently I use custom deserialization: /**
* InstanceEvent Deserializer
*
* @author L.cm
*/
public class InstanceEventDeserializer extends StdDeserializer<InstanceEvent> {
public InstanceEventDeserializer() {
super(InstanceEvent.class);
}
@Override
public InstanceEvent deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
JsonNode node = jsonParser.readValueAsTree();
String type = node.at("/type").asText();
InstanceId instance = InstanceId.of(node.at("/instance").asText());
long version = node.at("/version").asLong();
Instant timestamp = Instant.parse(node.at("/timestamp").asText());
if ("DEREGISTERED".equals(type)) {
return new InstanceDeregisteredEvent(instance, version, timestamp);
} else if ("ENDPOINTS_DETECTED".equals(type)) {
List<Endpoint> endpoints = JsonUtil.convertValue(node.at("/endpoints"), JsonUtil.getListType(Endpoint.class));
return new InstanceEndpointsDetectedEvent(instance, version, timestamp, Endpoints.of(endpoints));
} else if ("INFO_CHANGED".equals(type)) {
Map<String, Object> value = JsonUtil.convertValue(node.at("/info"), Map.class);
return new InstanceInfoChangedEvent(instance, version, timestamp, Info.from(value));
} else if ("REGISTERED".equals(type)) {
Registration registration = JsonUtil.convertValue(node.at("/registration"), Registration.class);
return new InstanceRegisteredEvent(instance, version, timestamp, registration);
} else if ("REGISTRATION_UPDATED".equals(type)) {
Registration registration = JsonUtil.convertValue(node.at("/registration"), Registration.class);
return new InstanceRegistrationUpdatedEvent(instance, version, timestamp, registration);
} else if ("STATUS_CHANGED".equals(type)) {
Map<String, Object> value = JsonUtil.convertValue(node.at("/statusInfo"), Map.class);
return new InstanceStatusChangedEvent(instance, version, timestamp, StatusInfo.from(value));
}
return null;
}
} |
@ChunMengLu Currently I think the best is to provide a jackson module with your deserializer by SBA as I'm currently refusing to taint the code with the jackson polymorphic deserialization stuff. |
I started the development of #684 and as pre-requirement I need a Jackson module for the InstanceEvent stuff. |
I just referenced a working state to the issue. @joshiste: Is that what you had in mind? Do you prefer...
My preference is the own "InstanceEventDeserializer" because of the minimal changes required. |
* Fix code style issue * Create own Jackson module for Spring Boot Admin Server preparation for #1348
My preference would be to pollute the core domain as little as possible with Jackson annotations. So either a custom deserializer or a mixin would be fine. |
Bug report
I customized eventstore and found that it is not good enough for deserialization.
I use jackson and need to customize a Deserializer like RegistrationDeserializer.
The text was updated successfully, but these errors were encountered: