Description
I have two quite different objects
public static GameCharacter sylvia() {
String characterName = "Sylvia the Hero";
String weaponName = "Gryphclaw";
int attack = 255;
Weapon weapon = new Weapon(weaponName, attack);
String armorName = "Starscale Armor";
int defense = 231;
Armor armor = new Armor(armorName, defense);
String _id = "sylv01";
List<Item> inventory = new ArrayList<Item>();
Potion potion = new Potion("Hi-Potion", 3);
inventory.add(potion);
Ether ether = new Ether("Mega Ether", 5, 200);
inventory.add(ether);
GameCharacter sylvia = new GameCharacter(characterName, weapon, armor, _id, inventory);
return sylvia;
}
public static GameCharacter sylviaEdited() {
String characterName = "Sylvia Zerin";
String weaponName = "Luberjack's Axe";
int attack = 7;
Weapon weapon = new Weapon(weaponName, attack);
String armorName = "Crude Mazoiscale Armor";
int defense = 13;
Armor armor = new Armor(armorName, defense);
String _id = "sylv01";
List<Item> inventory = new ArrayList<Item>();
Potion potion = new Potion("Hi-Potion", 2);
inventory.add(potion);
Tonic tonic = new Tonic("Full Tonic", 2, 100);
inventory.add(tonic);
GameCharacter sylvia = new GameCharacter(characterName, weapon, armor, _id, inventory);
return sylvia;
}
When comparing them like this:
GameCharacter sylvia = GameCharacters.sylvia();
GameCharacter sylviaEdited = GameCharacters.sylviaEdited();
DiffNode cityDelta
= objectDiffer.compare(sylvia, sylviaEdited);
...the resulting DiffNode tells reads / => UNTOUCHED
, even though the two compared objects are quite different.
Looking through the issues, I have found mentions of this being because the objects are POJOs and not JavaBeans. I have also seen mention of an Introspector and the IntrospectionConfiguration. I have been trying to figure something out with this, but have not come to a solution.
Is it possible to adequately compare objects like these?
public class GameCharacter {
@Id
public String _id;
public String name;
public Weapon weapon;
public Armor armor;
public List<Item> inventory;
public GameCharacter() {
}
public GameCharacter(String name, Weapon weapon, Armor armor, String _id, List<Item> inventory) {
this._id = _id;
this.name = name;
this.weapon = weapon;
this.armor = armor;
this.inventory = inventory;
}
}
The main question here is if it is possible to somehow use java-object-diff without the need to implement getters and setters.
For reference, you can find all the files and my attempts in the following repository:
https://github.com/Kira-Cesonia/tri-JaDe
Check out the delta.DeltaApplierTest