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

public field + getter for that field causes Enunciate error, even though Jackson is fine with it #367

Closed
ispringer opened this issue Apr 11, 2016 · 4 comments

Comments

@ispringer
Copy link

My team has a coding standard of making fields public on POJOs to reduce boilerplate code. For example:

public String name;

rather than:

private String name;
public String getName() { return name; }
public void setName(String name) { this.name = name; }

However, sometimes the POJO implements an interface that exposes the property, e.g.:

public interface HasName {
    String getName);
}

In that case the POJO ends up with a public field, as well as a getter for that field, i.e.:

public String name;
public String getName() { return name; }

Jackson 2, which we use for serialization, has no issues with this. It is smart enough to serialize to a single JSON property named "name" and deserialize that property back to the "name" field.

However, Enunciate chokes on it with this error:

[ENUNCIATE] Jackson naming conflicts have been found:
[ENUNCIATE] com.example.MyPojo: accessor "getName()" conflicts with accessor "name": both are named "name".
@stoicflame stoicflame added this to the 2.4.0 milestone Apr 11, 2016
@stoicflame
Copy link
Owner

Thanks for the report.

For now, Enunciate needs you to use the @JsonAutoDetect annotation to specify only field visibility.

For now, I'll keep this issue open to track the work to be smarter about conflict detection.

@sconstro
Copy link

sconstro commented May 3, 2016

+1. I use now Spring Hateoas and I cannot annotate classes (e.g. PagedResources)
Eventually , you can add some options to the jackson module configuration, something like field="visible" method="none"

@stoicflame
Copy link
Owner

I started looking at this in more detail, but I'm afraid I'm having a hard time reproducing the issue. I've tried to set up a project with beans with public fields and public associated getters, but Enunciate handles all the cases I've been able to come up with.

Any way you could put together a sample project that exposes the issue for me?

@stoicflame
Copy link
Owner

I'm going to close this since I haven't heard back and I haven't been able to reproduce it. I'd be happy to re-open as needed.

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

No branches or pull requests

3 participants