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

CsvMapper support for JsonView-aware schema generation #238

Closed
k-brooks opened this issue Jan 5, 2021 · 6 comments
Closed

CsvMapper support for JsonView-aware schema generation #238

k-brooks opened this issue Jan 5, 2021 · 6 comments

Comments

@k-brooks
Copy link

k-brooks commented Jan 5, 2021

The schema generation process through introspection by the CsvMapper class is very handy, it would be great if we could provide a view in this process to filter out fields which are irrelevant. This is especially important when outputting headers which one would like to be filtered.

@k-brooks k-brooks changed the title CsvMapper support for JsonView schema generation CsvMapper support for JsonView-aware schema generation Jan 5, 2021
@k-brooks
Copy link
Author

k-brooks commented Jan 5, 2021

Something as simple as the following would suffice

protected void _addSchemaProperties(
      CsvSchema.Builder builder,
      AnnotationIntrospector intr,
      boolean typed,
      JavaType pojoType,
      NameTransformer unwrapper, Class<?> view)
  {
    if (_nonPojoType(pojoType)) {
      return;
    }

    BeanDescription beanDesc = getSerializationConfig().introspect(pojoType);
    for (BeanPropertyDefinition prop : beanDesc.findProperties()) {
      if (!prop.couldSerialize()) {
        continue;
      }
      Class<?>[] viewArray = prop.findViews();
      if (viewArray != null && viewArray.length > 0 && !Arrays.asList(viewArray).contains(view)) {
        continue;
      }
...

@cowtowncoder
Copy link
Member

Hmmh. Interesting. I'll add this on my todo list to investigate for 2.13. And would be happy to get a PR too of course.

@k-brooks
Copy link
Author

I will start on this now, PR should be up soon

@k-brooks
Copy link
Author

Looks like this may already exist
#195

@k-brooks
Copy link
Author

Confirmed, already supported - sorry for the unnecessary issue

@cowtowncoder
Copy link
Member

lol. And I should have remembered having helper with the earlier PR :)

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