Parsing a nested JSON containment references list [message #1842423] |
Fri, 18 June 2021 04:56  |
Eclipse User |
|
|
|
Hello,
I am trying to define an model using Xcore for the following simplified JSON data:
(The category object contains many more attributes I have omitted here.)
{
"foo": "bar",
"categories": [
[
{
"categoryName": "root"
},
{
"categoryName": "a"
}
],
[
{
"categoryName": "root"
},
{
"categoryName": "b"
}
]
]
}
I have come up with the following model so far:
class Root {
String foo
contains CategoryPath[] categories
}
interface CategoryPath wraps org.eclipse.emf.common.util.EList<Category>
class Category {
String categoryName
}
This model generates the following Java Getter in my Root class, which is fine:
EList<EList<Category>> getCategories();
Now I am using the emfjson library, which moved to EMF.cloud recently, to parse the above JSON instance into EObjects. Sadly, this parsing fails because of the nested list.
Is this a limitation of the emfjson library or should I maybe model this differently?
Kind regards
Jan
[Updated on: Thu, 24 June 2021 05:14] by Moderator
|
|
|
|
|
|
|
|
Re: Parsing a nested JSON containment references list [message #1842671 is a reply to message #1842669] |
Mon, 28 June 2021 07:19   |
Eclipse User |
|
|
|
Thanks, I understand.
Flattening the list sadly discards some information, which is not obvious from my example: In this particular case above, the object belongs to the category path a/b. It could also belong to a/d/e and f/g/h for example. Having a flattened list of a, b, a, d, e, f, g, h would be problematic because I cannot restore the categories' hierarchy any more.
I will probably create a CategoryPath class holding a list of categories. This means, I need to preprocess the above JSON first, before being able to parse it then.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04108 seconds