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

Typed setters for the entities #45

Closed
GoogleCodeExporter opened this issue Apr 2, 2015 · 3 comments
Closed

Typed setters for the entities #45

GoogleCodeExporter opened this issue Apr 2, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

Не знаю, баг это или фича, но мне очень не 
нравится, что SnakeYAML 
вмешивается во внутреннюю логику 
сущностей.

Допустим есть класс:

<code>
class Entity {
    private int id;

    public Entity setId( int id ) {
       this.id = id;
       return this;
    }
}
</code>

Если написать фикстуры и попытаться 
синтезировать объект для данной 
сущности, мы получим ошибку о том, что поле 
`id` не было найдено. В тоже 
время при возвращаемом *setId* типе *void* - всё 
работает замечательно.

Original issue reported on code.google.com by LoRd1990 on 20 Jan 2010 at 2:25

@GoogleCodeExporter
Copy link
Author

Question: 
SnakeYAML does not work properly with the above class.
This is because setter returns an object instead of void.
==============================
Answer: 
this is not a SnakeYAML issue. This class violates the JavaBean spec.
I can imagine this was possibly desired by someone to implement a "chaining" 
style of 
coding, but this is no longer a correct JavaBean. The JavaBean spec requires 
that the 
return type of set* functions be 'void', and various tools and frameworks 
enforce 
this requirement. (XmlEncoder for instance)
If a chaining-style setter is desired, I'd recommend making this a separate 
method on 
the bean rather than replacing the standard setter.

Original comment by py4fun@gmail.com on 20 Jan 2010 at 3:06

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

py4fun is correct and naming things in a way spec says gives you (almost) what 
you want  out of the box.
But if you still need this one to work you may try to create corresponding 
BeanInfo class and provide correct 
PropertyDescriptor for the id giving setId as a setter name.

so it will be EntityBeanInfo in the same package as Entity or you have to set 
up Introspector BeanInfo paths and 
so on. 

(consult JavaBeans spec. 8 Introspection)

Original comment by alexande...@gmail.com on 20 Jan 2010 at 7:37

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

It is also possible to provide your own Constructor and Representer to work 
with the
Entity class.

Original comment by aso...@gmail.com on 22 Jan 2010 at 9:28

  • Changed state: WontFix
  • Added labels: ****
  • Removed labels: ****

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

1 participant