Created
August 12, 2015 03:04
-
-
Save mmacfadden/e0943c5cea2d8a30cf0c to your computer and use it in GitHub Desktop.
Demonstrates an issue with ODocument and setting array / list indices.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import com.orientechnologies.orient.core.record.impl.ODocument; | |
public class ODocumentSetAtListIndexTest { | |
public static void main(String[] args) { | |
ODocument doc = new ODocument(); | |
Map<String, Object> data = new HashMap<String, Object>(); | |
List<Object> parentArray = new ArrayList<Object>(); | |
parentArray.add(1); | |
parentArray.add(2); | |
parentArray.add(3); | |
Map<String, Object> object4 = new HashMap<String, Object>(); | |
object4.put("prop", "A"); | |
parentArray.add(object4); | |
data.put("array", parentArray); | |
doc.field("data", data); | |
// Should be "A". This works. | |
System.out.println(doc.field("data.array[3].prop")); | |
doc.field("data.array[3].prop", "B"); | |
// Should be "B". This works. | |
System.out.println(doc.field("data.array[3].prop")); | |
// Should be 1, this works. | |
System.out.println(doc.field("data.array[0]")); | |
doc.field("data.array[0]", 5); | |
// Should be "5", this does not work, it prints 1. | |
System.out.println(doc.field("data.array[0]")); | |
// As you can see we have created a property on the "data" object with a key of | |
// "array[0]" and a value of 5. But we can never access that field. Because the | |
// field "getter", properly parses the array subscript, but the field "setter" does | |
// not. | |
System.out.println(doc.toJSON()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment