Skip to content
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

Support JsonTypeInfo.Id.MARKER_FIELD request #1100

Closed
lex-em opened this issue Jan 28, 2016 · 4 comments
Closed

Support JsonTypeInfo.Id.MARKER_FIELD request #1100

lex-em opened this issue Jan 28, 2016 · 4 comments

Comments

@lex-em
Copy link

lex-em commented Jan 28, 2016

Hi, does this capability can be realized?

@JsonTypeInfo(use = JsonTypeInfo.Id.MARKER_FIELD)
@JsonSubTypes({
        @JsonSubTypes.Type(value = ComplexTypeDto.class, name = "fields")
})
public class SimpleTypeDto {

    private String id;

    private String name;

   ...
}
public class ComplexTypeDto extends SimpleTypeDto {
    private Collection<FieldDto> fields;
}

Serialization example data:

List<SimpleTypeDto> types = new ArrayList<>();
types.add(new SimpleTypeDto(123, "simple type"));
types.add(new ComplexTypeDto(345, "complex type", Arrays.asList(new FieldDto("field")));

Json:

[
  {
    "id":123,
    "name":"simple type"
  },
  {
    "id":345,
    "name":"complex type",
    "fields":[
        {
             "name":"field"
        }
    ]
  }
]
@lex-em
Copy link
Author

lex-em commented Jan 28, 2016

for more convenience can be added annotation @JsonSubTypesByFields (with multiple names):

@JsonTypeInfo(use = JsonTypeInfo.Id.MARKER_FIELD)
@JsonSubTypesByFields({
        @JsonSubTypesByFields.Type(value = ComplexTypeDto.class, names = {"fields"})
})
public class SimpleTypeDto {

    private String id;

    private String name;

   ...
}

@lex-em lex-em changed the title Add support JsonTypeInfo.Id.MARKER_FIELD Support JsonTypeInfo.Id.MARKER_FIELD request Jan 28, 2016
@cowtowncoder
Copy link
Member

There is an existing issue for something along those lines, to allow inference of type information from existence of fields: #43

I don't think anyone is actively implementing such functionality: the main problem is that this does require holding the whole JSON Object in memory (currently this is not needed; property values are handled incrementally, with some exceptions related to buffering of type and/or object ids).

I will add a link to this issue from there (since these are additional ideas), but will close this as duplicate.
Feel free to add notes to #43 as relevant.

@lex-em
Copy link
Author

lex-em commented Jan 29, 2016

@cowtowncoder thank you for detailed answer

@cowtowncoder
Copy link
Member

@lex-em no problem, thank you for suggestion -- this is desired piece of functionality, but unfortunately not yet implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants