Hi Paul, Hugi,
Thanks for your very useful feedback :-)
The data looks like a tree (e.g. the AjaxTreeModel in the Ajax
framework). Each node of the tree has a title (like a folder name for
example). Each folder contains files, and can contain a sub-folder as
well.
I rewrote the code to avoid dictionaries as Hugi suggested. Like this I
can access the folders and the files in the folder:
String content = new String(Files.readAllBytes(Paths.get(inputFile)));
Node rootNode;
rootNode = objectMapper.readValue(content, Node.class); // Jackson
List<Node> children = rootNode.getChildren().get(2).getChildren();
children.forEach(e -> log.info(e.getTitle()));
Now the problem:
Depending on how many subfolders there are I should use either
children1 or children2:
List<Node> children1 =
rootNode.getChildren().get(2).getChildren().get(0).getChildren();
List<Node> children2 = rootNode.getChildren().get(2).getChildren();
Is there a way to get all the files (children.getTitle) in all the
subfolders? Is should only find the file names, not the name of the
subfolder. Both are retreived from the rootNode object with
rootNode.getChildren().getTitle(), but one is a folder name and the
other a file name.
Last question: how to add a list (called children) into the editing
context? I can only think of this:
List<Node> children =
rootNode.getChildren().get(2).getChildren();
ERXEC ec = new ERXEC();
ChildrenEO child = new ChildrenEO();
for (Node node : children) {
child.setTitle(node.getTitle());
child.setDateAdded(node.getDateAdded());
[...many more...]
}
ec.insertObject(child);
ec.saveChanges();
Is there a better way to convert a list to an EO automatically for all
the items in the list?
Thanks in advance, Bart
On Sun, 2016-02-07 at 09:55 +1030, Paul Hoadley wrote:
> Hi Bart,
>
> On 7 Feb 2016, at 9:06 am, jazzsalsa <[email protected]> wrote:
>
> > This really helps. I will give that I try. How do I add it now to
> > the database uisng the EOF?
>
> Hugi’s advice is about round-tripping to and from JSON as a
> serialisation format, because you mentioned "a nested JSON object
> which is converted to a dictionary” in your original post. So it’s an
> alternative to the “converted to a dictionary” part. If you also need
> to persist this data using EOF, you’d make the objects in the object
> graph (assembled from the JSON) Enterprise Objects, and then save
> them out in the usual way.
>
> > Add them to a NSDictionary with a loop and store in the editing
> > context?
>
> The idea here would be to drop the use of dictionaries if you can.
> But I think we’re approaching the limit of what we can suggest
> without knowing some more detail (at a higher level) about what
> you’re trying to do.
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]