Using Retrofit and GreenDao with nested json objects

I want to combine Retrofit and GreenDao but I have a problem with nested Json-Objects. My nested fields remain empty.

This is the Json DataStructure

[ { "id": 1, "street": "Streetname", "zipcode": 12345, "city": "MyCity", "phone_number": "+123456789", "position": "12.0000, 9.0000", "company": { "title": "CompanyName", "group": { "title": "GroupName" } } } ]

My DaoGenerator looks like this

Entity customItem = schema.addEntity("CustomItems"); customItem.addIdProperty(); customItem.addStringProperty("street"); customItem.addIntProperty("zipcode"); customItem.addStringProperty("city"); customItem.addStringProperty("phone_number"); customItem.addStringProperty("position"); Entity company = schema.addEntity("Company"); company.addIdProperty(); company.addStringProperty("title"); Entity group = schema.addEntity("Group"); group.addIdProperty(); group.addStringProperty("title"); Property companyPropId = customItem.addLongProperty("companyId").notNull().getProperty(); customItem.addToOne(company, companyPropId); Property groupPropId = company.addLongProperty("groupId").notNull().getProperty(); company.addToOne(group, groupPropId);

My problem is that customItem.getCompany() returns null but the values "id" to "position" are fine. I'm not sure what the problem is as my CustomItem class contains the member

private Company company;

and the setter for the company and I can't see any typo.

public void setCompany(Company company) { if (company == null) { throw new DaoException("To-one property 'companyId' has not-null constraint; cannot set to-one to null"); } synchronized (this) { this.company = company; companyId = company.getId(); company__resolvedKey = companyId; } }

-------------Problems Reply------------

I got it running but I had multiple problems.

1) When I wanted to persist the CustomItem, Company, and Group I had the problem that the getters getCompany() and getGroup() returned null because they don't return the member directly but fetch it from the DB. Therefore I added a getter to the generated CustomItem entity class that simply returns the company member. Now I was able to insert company to the db. The getter looks like this:

// KEEP METHODS - put your custom methods here
public Company getCompanyLocal() {
return company;
}
// KEEP METHODS END

The same works for Company and Group, too. But there was another issue...

2) The second problem was the entity 'Group' as 'group' is a reserved SQL keyword. I see one solution and a bad workaround to this problem:

  • The good one is to change you json data from 'group' to i.e. 'business_group' and according to that change your DAOs. Done.
  • The bad workaround if you are in the same situation like me where you can't change the json you could do the following. I don't persist the group at all but can access it via the company. It somehow appears there. Therefore I added a getter to my Company class like the getter of CustomItem above. It works but you should avoid this. As you can't query your DB for group or load group from db.
Category:android Views:18 Time:2019-03-18

Related post

  • Angular ng-repeat with nested json objects? 2015-02-02

    I have a JSON object, represented as such: { "orders" : [ { "ordernum" : "PRAAA000000177800601", "buyer" : "Donna Heywood" "parcels" : [ { "upid" : "UPID567890123456", "tpid" : "TPID789456789485" }, { "upid" : "UPID586905486090", "tpid" : "TPID343454

  • Using .onKeyUp and .onChange with Javascript DOM objects 2009-04-25

    I'm having a weird problem with some Javascript/DOM code I've ben playing with. I'm trying to assign the .onKeyUp and .onChange events/methods to a text input like so: form.elements["article"].onkeyup = "alert('test');"; Oddly, assigning using that m

  • Convert a json with nested json into an object in c#? 2011-03-11

    I've seen a fair number of questions along these lines and have tried a number of the suggested solutions, but just can't seem to crack this. I'm trying to convert a JSON into an object within c#. The JSON in question has an unusual (for me) layout a

  • can't get nested JSON object with recurring name 2012-02-21

    I'm quite new to JSON so the following might be a trivial problem, but I could not find any comparable question on stackoverflow, so: I would like to get a nested JSON object like: pizza.topping.rating but when accessing it says undefined, although c

  • Create nested json object using python jsonpickle 2012-04-02

    I want to build nested json object using python jsonpickle, something like this {"key": "value", "key2": { "key2": "value2", "key": "value"} } } using jsonpickele set value to variable name and def __init__(self, value): self.key1 = value self.key2 =

  • Iterate over nested JSON Object using JS 2012-04-22

    I have this JSON Object which I receive from the api.moviedb.com It is pretty nested JSON Object and I m having issues while retrieving specific data from it. Here's the Gist of the object I need to get specifically the "url" from the image posters a

  • Creating a nested JSON object 2011-09-12

    I am trying to create a complex nested object like this: { "user":{ "type":"facebook", "first_name":"harsha", "last_name":"mv", "gender":"male" }, "friends":[ { "id":"23", "name":"Vachana" }, { "id":"23", "name":"Jyosna" }, { "id":"23", "name":"Avina

  • How to make a nested Json object in Java? 2012-03-29

    I want to program a nested JSON Object for my Android device, but how? I have only basic experience with Json, so I would appreciate if someone could help me with the following code: { "command": "login", "uid": "123123123", "params": { "username": "

  • How to use google app engine with ajax (json)? 2011-02-24

    How to use google app engine with ajax (json)? Now I have this but I got this error: raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded from google.appengine.ext import webapp from google

  • Handling Nested JSON Object via Facebook C# SDK 2011-04-19

    Greetings and many thanks to the Stack Overflow community for all of the other awesome posts about the Facebook c# SDK. I have ran into a little challenge here and unfortunately I have not been able to find a previously posted solution. How are you g

  • Using REST in Place with nested attributes 2011-07-17

    REST in Place is a fantastic rails plugin by Jan Varwig that uses AJAX to edit object attributes inline. It was very easy to set up, simple to implement, and generally just works well. I've read around online of people using REST in Place with nested

  • Using telerik's RadAjaxManager with nested ASCX controls 2011-07-20

    I want to use telerik's RadAjaxManager with nested ASCX controls I have the following setup: Page ascx1 ascx2 ascx2 is nested in ascx1 which is in Page. I have a RadAjaxManager on 'Page'. From a control in ascx2, I invoke a javascript method which ca

  • Query nested JSON objects 2013-03-28

    I'm brand new to javascript and json and can't find any examples that explain how to get nested json objects. This works great: var someJson={"name":"spuder"}; alert(someJson.name); //alert shows spuder This returns undefined: //This is the json from

  • http get with async on android with a JSON Object 2014-01-23

    Hey I am trying to call an http get with a JSON Object I pass through my Async Task but I am having a hard time figuring out how to get the response, and more importantly how to send the get with the request in it... Here is my current code: private

  • WPF: How to implement Drag and Drop with nested (hierarchical) controls 2009-02-20

    Using WPF I've succeeded at implementing drag and drop to rearrange items within a list(view or box) and also to drag and drop items between lists. Now I am trying figure out how to implement drag and drop with NESTED lists. For instance I have a lis

  • Can anyone please explain to me what max_input_nesting_level is used for and what is nesting depth? 2009-12-12

    Can anyone please explain to me what max_input_nesting_level is used for and what is nesting depth with a detailed example. Because as i am a newbie i need to know in depth. Thanks n advance --------------Solutions------------- I assume you know the

  • Is there a way to wrap a tkinter GUI in a class that can be created and interacted with from another object? (*without* hanging in mainloop) 2011-04-05

    Is there a way to wrap a tkinter GUI in a class that can be created and interacted with from another object? For this to be really useful, the class has to work so mainloop or its equivalent doesn't hold the application. If so, can someone point me t

  • Use join() and where() with update() 2011-11-18

    Can i use join() and where() with update() in query builder? $q = Yii::app()->db->createCommand() ->update('table',array('a'=>0)) ->join('join statement') ->where('where statement') ->query(); I get error like this Call to a memb

  • Calling a function and pass it a json object 2012-03-09

    I have a json object named data like below And I have a function denomination in a string like below test is the name of the function I would like to call and pass it the json object data. here is the test function: test = function (data) { alert('I

  • Is it possible to use @PrePersist and @PreUpdate with eBean and Play! 2.0? 2012-03-29

    I want to know if is it possible to use @PrePersist and @PreUpdate with Ebean and Play! 2.0. If so how is this feature activated. I've seen that there was a pull request adding this feature a month ago, but I can't make this work on Play 2.0. Thanks

  • there is performance hit or some other negative factor when using 'preg_replace' and array with several indexes? 2011-06-20

    there is performance hit or some other negative factor when using 'preg_replace' and array with several indexes? $string = 'The quick brown fox jumped over the lazy dog.'; $patterns[0] = '/quick/'; $patterns[1] = '/brown/'; ... $patterns[100] = '/fox

  • Is there a simple way to use RSQLite and `sqldf` with more than 999 variables? 2011-11-06

    Is there a simple way to use RSQLite and sqldf with more than 999 variables? This question was raised also here. An answer on R-sig-DB "The reason why this doesn't work seems to be SQLITE_MAX_VARIABLE_NUMBER in the sqlite source (in RSQLite) is curre

  • Using JMockit and TestNG with Spring framework 2012-03-02

    Spring framework has great integration with jUnit and EasyMock. Does anyone have experience using JMockit and TestNG with Spring framework? --------------Solutions------------- I have experience with TestNG with Spring framework. spring-test.jar libr

  • How do I use Open and Open With for multiple files? 2013-03-30

    When I select one file/folder, I can use Open and Open With fine... select a few more and Open With is disabled. Select even more and eventually even Open disappears. Can I disable this? I want to be able to use Open and Open With for multiple files.

  • Since upgrading to Windows 7 I can no longer upload files greater than 1500kb to send with messages. I have tried using IE8 and Firefox with the sames results. Is there a parameter that needs to be changed somewhere? 2014-02-15

    Since upgrading to Windows 7 I can no longer upload files greater than 1500kb to send with messages. I have tried using IE8 and Firefox with the sames results. Is there a parameter that needs to be changed somewhere? --------------Solutions----------

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.087 (s). 11 q(s)