-
-
Notifications
You must be signed in to change notification settings - Fork 811
JsonGenerator#writeTypePrefix writes an id "null" and cannot be set up to skip the id completely #584
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
Comments
Hmmh. I do not recall logic off-hand, but it seems to me that there is no point in attempting to write type id of
I mention (2) mostly since the idea of making generator do more was to give more power to format-specific backends which know more about details of how to embed type ids (YAML, XML, Avro f.ex) and possible even changes to type ids. So... I think we could consider blocking call (that is, approach (1)) for 2.11. Do you have a sample use case that you think should work, but doesn't? I think I understand this scenario, but just want to double-check as this is bit intricate area. |
I'll speak to the relevant people at work to see if I can contribute something from the office otherwise I'll put something more generic together at home over the next few days. Do you have any tests in jackson-core that would be a good starting point for a failing test around this? |
Unfortunately I think that this specific feature sort of falls between components so there might not be existing tests specifically targeting interaction. There are many tests for type id handling (in jackson-databind) but those operate at bit higher level, testing round-trip handling (writing polymorphic values, reading back). But I think tests probably should go in |
Note to self: place where
where |
We also likely need to have the same check in |
@johnjohndoe Hmmh. Yes. |
@cowtowncoder Typo-autocomplete? |
@johnjohndoe Agh. Yes, thank you for pointing out. @jonfreedman As per above... yes. :) |
@cowtowncoder are these changes correct in public WritableTypeId writeTypePrefix(JsonGenerator g, WritableTypeId idMetadata) throws IOException {
this._generateTypeId(idMetadata);
if (idMetadata.id == null) {
g.writeStartObject();
return idMetadata;
} else {
return g.writeTypePrefix(idMetadata);
}
}
public WritableTypeId writeTypeSuffix(JsonGenerator g, WritableTypeId idMetadata) throws IOException {
if (idMetadata.id == null) {
g.writeEndObject();
return idMetadata;
} else {
return g.writeTypeSuffix(idMetadata);
}
} |
@beatfreaker I don't think use of Instead, this:
does pass all unit tests, but not sure if that would be desirable change. |
@jonfreedman Ok it's been a while but as I am trying to close 2.12.0 feature set, was wondering if you had any further ideas here? As per my note above, simply skipping call on |
Ok, another year, not much progress alas (my fault). I am preparing for 2.13.1 patch release, so the likeliest chance to change this would be for 2.14.0 (for which there is branch but no firm release plans; progress slower than with 2.13). |
Thank you for keeping this on your radar |
Created FasterXML/jackson-databind#3373 to implement. Would REALLY appreciate a test of some kind, after implementation; will add notes on issue linked-to. |
Implemented this on |
Unfortunately I no-longer have access to the codebase where I was using this, and I'm currently working in C# rather than Java... Based on my original issue I think the breaking test would be something along the lines of attempting to handle a custom type with type annotation and validating how null values are handled. |
@jonfreedman Np. I think you did actually mention this. Appreciate all the help so far. Will see if someone else had similar needs or issues. |
Will close for now, assume that databind-side fix resolves the issue. If not, we'll need a new issue to be filed, I think, with details of what is still needed etc. |
I have a
TypeIdResolver
implementation which works around generic type erasure to allow marshaling/unmarshaling of a parameterized type. This works fine when the underlying parameterized type maps directly onto a JSON type e.g.java.lang.Double
but when it's a type that needs to be converted to a JSON string e.g.java.time.LocalDate
then myTypeIdResolver
is asked for a type and I can either return the String "java.time.LocalDate" or a null value.If I return a null then
TypeSerializerBase#handleMissingId
currently does nothing as per FasterXML/jackson-databind#633 but it looks like the control of how to write the typeId is now handed off toJsonGenerator#writeTypePrefix
@ https://github.com/FasterXML/jackson-core/blob/master/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java#L1061It would be great if writeTypePrefix did nothign if
typeIdDef.id
is null - I don't want to monkey-patch this unless it's going to make it into master...The text was updated successfully, but these errors were encountered: