yamlbeans icon indicating copy to clipboard operation
yamlbeans copied to clipboard

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

Open NemesisMate opened this issue 8 years ago • 2 comments

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 avatar Jun 28 '16 15:06 NemesisMate

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).

NemesisMate avatar Jun 28 '16 15:06 NemesisMate

@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.

Mr14huashao avatar May 19 '20 07:05 Mr14huashao