Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Enhancement] Make setBeanProperties to not depend on it field type. #53

Open
NemesisMate opened this issue Jun 28, 2016 · 2 comments
Open

Comments

@NemesisMate
Copy link
Contributor

NemesisMate commented Jun 28, 2016

The field dependency for the bean property way is great to allow making the bean transient (it isn't currently working, and I wonder if it is intended to) but with this it is impossible to make some tricks as set a String and then, in the getter/setter make wathever magic to de/serialize de field type. ie:

!thing
template: "t1"

and after in code:

TemplateType template;

String getTemplate() {
   return template.getName();
}

void setTemplate(String template) {
  this.template = getTemplateForName(template);
}
@NemesisMate
Copy link
Contributor Author

More examples:

Vector3 jumpForce;

Vector3 getJumpForce() {
   return jumpForce;
}
void setJumpForce(Vector3 force) {
   this.jumpForce = force;
}

Vector3 getJumpForcePerWeight() {
   return this.jumpForce.div(weight);
}
void setJumpForcePerWeight(Vector3 force) {
   this.jumpForce = force.mul(weight);
}

The current way (in 1.09, previously in 1.08 this was possible) doesn't allow these tricks. However the "don't verify the field type" enhancement wouldn't work neither. Maybe it would be better more options, like setBeanFieldRequired(boolean) and setBeanFIeldTypeMatch(boolean).

@Mr14huashao
Copy link
Collaborator

@NemesisMate
setting:

yamlWriter.getConfig().setPrivateFields(true);
yamlReader.getConfig().setPrivateFields(true);
private TemplateType template;

String getTemplate() {
   return template.getName();
}

void setTemplate(String template) {
  this.template = getTemplateForName(template);
}

The template field is not a standard get, set method can also be serialized and deserialized.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

2 participants