Support
Quality
Security
License
Reuse
kandi has reviewed jsonschema2pojo and discovered the below as its top functions. This is intended to give you an instant insight into jsonschema2pojo implemented functionality, and help decide if they suit your requirements.
Getting started
How to contribute
Reference
Latest Javadocs
Documentation for the Maven plugin
Documentation for the Gradle plugin
Documentation for the Ant task
Downloads
Mailing list
jsonschema2pojo
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
<targetPackage>com.example.types</targetPackage>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Retrofit Body isn't showing desired response from Nested JSON
public class User {
@SerializedName("age")
@Expose
...
@Override
String toString() {
return "age: " + age + " avatar: " + avatar + ....;
}
}
Json values are null while some not with GSON parsing
@Generated("jsonschema2pojo")
public class Current {
@SerializedName("temp_c")
@Getter
@Setter
@Expose
private Double tempC;
@SerializedName("temp_f")
@Getter
@Setter
@Expose
private Double tempF;
@JsonProperty("condition")
@Getter
@Setter
@Expose
private Condition condition;
@SerializedName("feelslike_c")
@Getter
@Setter
@Expose
private Double feelslikeC;
@SerializedName("feelslike_f")
@Setter
@Getter
@Expose
private Double feelslikeF;
@JsonProperty("uv")
@Getter
@Setter
@Expose
private Double uv;
Parsing a nested json using gson
Type type = new TypeToken<Map<String, ArrayList<JsonFormatter>>>() {}.getType();
Map<String, ArrayList<Example>> nodeProperties = gson.fromJson(json.toString(), type);
How to deserialize JSON data from an IEX Cloud batch endpoint
class Root {
private Map<String, Stock> stocks = new LinkedHashMap<>();
@JsonAnyGetter
public Map<String, Stock> getStocks() {
return this.stocks;
}
@JsonAnySetter
public void addStock(String name, Stock value) {
this.stocks.put(name, value);
}
}
class Stock {
private Quote quote;
public Quote getQuote() {
return this.quote;
}
public void setQuote(Quote quote) {
this.quote = quote;
}
}
class Quote {
private String symbol;
private BigDecimal latestPrice;
public String getSymbol() {
return this.symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public BigDecimal getLatestPrice() {
return this.latestPrice;
}
public void setLatestPrice(BigDecimal latestPrice) {
this.latestPrice = latestPrice;
}
}
-----------------------
class Root {
private Map<String, Stock> stocks = new LinkedHashMap<>();
@JsonAnyGetter
public Map<String, Stock> getStocks() {
return this.stocks;
}
@JsonAnySetter
public void addStock(String name, Stock value) {
this.stocks.put(name, value);
}
}
class Stock {
private Quote quote;
public Quote getQuote() {
return this.quote;
}
public void setQuote(Quote quote) {
this.quote = quote;
}
}
class Quote {
private String symbol;
private BigDecimal latestPrice;
public String getSymbol() {
return this.symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public BigDecimal getLatestPrice() {
return this.latestPrice;
}
public void setLatestPrice(BigDecimal latestPrice) {
this.latestPrice = latestPrice;
}
}
-----------------------
class Root {
private Map<String, Stock> stocks = new LinkedHashMap<>();
@JsonAnyGetter
public Map<String, Stock> getStocks() {
return this.stocks;
}
@JsonAnySetter
public void addStock(String name, Stock value) {
this.stocks.put(name, value);
}
}
class Stock {
private Quote quote;
public Quote getQuote() {
return this.quote;
}
public void setQuote(Quote quote) {
this.quote = quote;
}
}
class Quote {
private String symbol;
private BigDecimal latestPrice;
public String getSymbol() {
return this.symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public BigDecimal getLatestPrice() {
return this.latestPrice;
}
public void setLatestPrice(BigDecimal latestPrice) {
this.latestPrice = latestPrice;
}
}
Jackson Deserializing an array of objects into an array list
Rows rows = mapper.readValue(new File(ClientsRecordsPath), Rows.class);
-----------------------
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
Rows rowsArrayList = mapper.readValue(new File(ClientsRecordsPath), Rows.class);
JSON array to Array objects...
Row(userId=1, commission=0.0, swaps=-1.87, profit=-73.39, comment=MAM|12345678|10020031)
Row(userId=2, commission=0.0, swaps=0.0, profit=12.23, comment=PAMM|12345678|10229501)
Row(userId=3, commission=0.0, swaps=0.0, profit=396.77, comment=PAMM|12345678|10229501)
List<Row> rows = Arrays.asList(mapper.treeToValue(mapper.readTree(new File(ClientsRecordsPath)).get("rows"), Row[].class));
rows.forEach(System.out::println);
Row(userId=1, commission=0.0, swaps=-1.87, profit=-73.39, comment=MAM|12345678|10020031)
Row(userId=2, commission=0.0, swaps=0.0, profit=12.23, comment=PAMM|12345678|10229501)
Row(userId=3, commission=0.0, swaps=0.0, profit=396.77, comment=PAMM|12345678|10229501)
-----------------------
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
Rows rowsArrayList = mapper.readValue(new File(ClientsRecordsPath), Rows.class);
JSON array to Array objects...
Row(userId=1, commission=0.0, swaps=-1.87, profit=-73.39, comment=MAM|12345678|10020031)
Row(userId=2, commission=0.0, swaps=0.0, profit=12.23, comment=PAMM|12345678|10229501)
Row(userId=3, commission=0.0, swaps=0.0, profit=396.77, comment=PAMM|12345678|10229501)
List<Row> rows = Arrays.asList(mapper.treeToValue(mapper.readTree(new File(ClientsRecordsPath)).get("rows"), Row[].class));
rows.forEach(System.out::println);
Row(userId=1, commission=0.0, swaps=-1.87, profit=-73.39, comment=MAM|12345678|10020031)
Row(userId=2, commission=0.0, swaps=0.0, profit=12.23, comment=PAMM|12345678|10229501)
Row(userId=3, commission=0.0, swaps=0.0, profit=396.77, comment=PAMM|12345678|10229501)
-----------------------
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
Rows rowsArrayList = mapper.readValue(new File(ClientsRecordsPath), Rows.class);
JSON array to Array objects...
Row(userId=1, commission=0.0, swaps=-1.87, profit=-73.39, comment=MAM|12345678|10020031)
Row(userId=2, commission=0.0, swaps=0.0, profit=12.23, comment=PAMM|12345678|10229501)
Row(userId=3, commission=0.0, swaps=0.0, profit=396.77, comment=PAMM|12345678|10229501)
List<Row> rows = Arrays.asList(mapper.treeToValue(mapper.readTree(new File(ClientsRecordsPath)).get("rows"), Row[].class));
rows.forEach(System.out::println);
Row(userId=1, commission=0.0, swaps=-1.87, profit=-73.39, comment=MAM|12345678|10020031)
Row(userId=2, commission=0.0, swaps=0.0, profit=12.23, comment=PAMM|12345678|10229501)
Row(userId=3, commission=0.0, swaps=0.0, profit=396.77, comment=PAMM|12345678|10229501)
Spring boot app stops with UnknownContentTypeException when trying to return JSON response from endpoint
package com.example.swapispring.controller;
import com.example.swapispring.entity.responseOfInhabitantsFromPlanetName.InitialResponseOfPlanets;
import com.example.swapispring.entity.responseOfInhabitantsFromPlanetName.Planet;
import com.example.swapispring.entity.responseOfInhabitantsFromPlanetName.Residents;
import com.example.swapispring.entity.responseOfStarshipsFromCharacterName.Character;
import com.example.swapispring.entity.responseOfStarshipsFromCharacterName.InitialResponseOfCharacters;
import com.example.swapispring.entity.responseOfStarshipsFromCharacterName.Starship;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
@RestController
@RequestMapping("/api")
public class Controller {
@Autowired
private RestTemplate restTemplate;
//Endpoint to return JSON of starships that the given character has piloted
@RequestMapping("/starships/{characterName}")
public ArrayList<Starship> getStarships(@PathVariable("characterName") String characterName) {
//Rest Template get for initial response JSON (The character)
InitialResponseOfCharacters initialResponseOfCharacters = restTemplate.getForObject("https://swapi.dev/api/people/?search=" + characterName, InitialResponseOfCharacters.class);
//Array list of starships to be returned as the final response
ArrayList<Starship> results = new ArrayList<>();
assert initialResponseOfCharacters != null;
if (initialResponseOfCharacters.getCharacters().size() == 1) {
for (Character tempCharacter : initialResponseOfCharacters.getCharacters()) {
for (String tempStarship : tempCharacter.getStarships()) {
tempStarship = tempStarship.replaceAll("http", "https");
Starship resultingObject = restTemplate.getForObject(tempStarship, Starship.class);
results.add(resultingObject);
}
}
//error handling
} else {
Starship starshipError = new Starship();
starshipError.setAdditionalProperty("Error", "More than one or no characters found please refine your search");
results.add(starshipError);
}
return results;
}
JSON Objects with Field that is sometimes an Array
YourTargetClass result = mapper.reader(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.forType(YourTargetClass.class)
.readValue(json);
Create a java model from json response
package com.test.test;
import java.util.List;
class Prediction{
public String label;
public double probability;
}
public class Test{
public boolean success;
public List<Prediction> predictions;
}
-----------------------
serverResponse.getPredictions().get(0).getLabel()
serverResponse.getPredictions().get(0).getProbability()
I can't get the JSON data "Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $"
public class temsData{
private String idTeam;
private String idSoccerXML;
private String idAPIfootball;
public String getidTeam() {
return idTeam;
}
public String getidSoccerXML() {
return idSoccerXML;
}
public String getidAPIfootball() {
return idAPIfootball;
}
// and add your more data like this ...
}
public class TeamList {
private List<temsData> teams;
public List<temsData> getTems() {
return teams;
}
}
-----------------------
public class temsData{
private String idTeam;
private String idSoccerXML;
private String idAPIfootball;
public String getidTeam() {
return idTeam;
}
public String getidSoccerXML() {
return idSoccerXML;
}
public String getidAPIfootball() {
return idAPIfootball;
}
// and add your more data like this ...
}
public class TeamList {
private List<temsData> teams;
public List<temsData> getTems() {
return teams;
}
}
Room with complex Json structure
class OrgWithLoginAndStyle {
/* Note use Query that
JOINS the Orgtable with the Login table
and JOINS the Orgtable with the Style table
*/
@Embedded
OrgTable orgTable;
@Embedded
LoginOptionsTable loginOptionsTable;
@Embedded
StyleTable styleTable;
}
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
class OrganizationWithLoginOptionsAndWithStyles {
@Embedded
OrgTable orgTable;
@Relation(entity = LoginOptionsTable.class,parentColumn = "loginOptionsId",entityColumn = "loginOpnId")
List<LoginOptionsTable> loginOptionsTables;
@Relation(entity = StyleTable.class,parentColumn = "stId",entityColumn = "styleId")
List<StyleTable> styleTables;
}
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Entity(foreignKeys = {@ForeignKey(entity = StyleTable.class, parentColumns =
"styleId", childColumns = "stId"),
@ForeignKey(entity = LoginOptionsTable.class, parentColumns =
"loginOpnId", childColumns = "loginOptionsId")
})
@Dao
public interface OrgDAO {
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Insert
long insertStyle(StyleTable styleTable);
@Insert
long insertLoginOptions(LoginOptionsTable loginOptionsTable);
}
public class MainActivity extends AppCompatActivity {
OrgLoginStyleDatabase db;
OrgDAO dao;
public static final String TAG = "OLSINFO";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Room.databaseBuilder(this,OrgLoginStyleDatabase.class,"orgloginoptionsstyle.db")
.allowMainThreadQueries()
.build();
dao = db.getOrgDao();
StyleTable s1 = new StyleTable();
s1.bannerBackgroundColor = "X";
s1.bannerTextColor = "X";
s1.baseTextSize = 20;
s1.bodyBackgroundColor = "X";
s1.bodyTextColor = "X";
s1.buttonBackgroundColor = "X";
s1.buttonTextColor = "X";
s1.htmlWrapper = "X";
s1.navigationBackgroundColor = "X";
s1.navigationTextColor = "X";
s1.styleId = 100;
s1.topBarBackgroundColor = "X";
s1.topBarLabel = "X";
s1.topBarTextColor = "X";
long s1Id = dao.insertStyle(s1);
LoginOptionsTable l1 = new LoginOptionsTable();
l1.allowedEmailDomain = "Y";
l1.authorizationEndpointUri = "Y";
l1.clientId = "Y";
l1.clientSecret = "Y";
l1.description = "Y";
l1.loginOpnId = 1000;
l1.name = "Y";
l1.nonce = "Y";
l1.redirectUri = "Y";
l1.restrictedEmailDomain = "Y";
l1.state = "Y";
l1.title = "Y";
l1.url = "Y";
long l1Id = dao.insertLoginOptions(l1);
OrgTable o1 = new OrgTable();
o1.description = "Z";
o1.id = 10000;
o1.loginOptionsId = l1Id;
o1.stId = s1Id;
dao.insertOrg(o1);
List<OrgTable> orgTableList = dao.getOrganizations();
for(OrgTable o: orgTableList) {
logOrgTable(o,"FROM getOrganizations -> ");
}
List<OrganizationWithLoginOptionsAndWithStyles> organizationsLoginsAndStylesList = dao.getOrganizationsLoginsAndStyles();
for(OrganizationWithLoginOptionsAndWithStyles owloaws: organizationsLoginsAndStylesList) {
logOrgTable(owloaws.orgTable,"FROM (@Relations) getOrganizationsLoginsAndStyles -> ");
for(LoginOptionsTable lot: owloaws.loginOptionsTables) {
logLoginOptionsTable(lot,"\t");
}
for(StyleTable s: owloaws.styleTables) {
logStyleTable(s,"\t");
}
}
List<OrgWithLoginAndStyle> owlas = dao.getOrganizationLoginAndStyle();
for(OrgWithLoginAndStyle o: owlas) {
logOrgTable(o.orgTable,"FROM (@Embeddeds) getOrganizationLoginAndStyle -> ");
logLoginOptionsTable(o.loginOptionsTable,"\t");
logStyleTable(o.styleTable,"\t");
}
}
private void logOrgTable(OrgTable o,String preamble) {
Log.d(TAG,preamble + "OrgTable Description = " + o.description + " ID = " + o.id);
}
private void logStyleTable(StyleTable s, String preamble) {
Log.d(TAG,preamble + "StyleTable Description = " + s.topBarTextColor + " ID =" + s.styleId);
}
private void logLoginOptionsTable(LoginOptionsTable l, String preamble) {
Log.d(TAG,preamble + "LoginOptionsTable Description = " + l.description + " ID = " + l.loginOpnId);
}
}
2021-04-12 21:51:50.981 D/OLSINFO: FROM getOrganizations -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: FROM (@Relations) getOrganizationsLoginsAndStyles -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.987 D/OLSINFO: StyleTable Description = X ID =100
2021-04-12 21:51:50.989 D/OLSINFO: FROM (@Embeddeds) getOrganizationLoginAndStyle -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.989 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.989 D/OLSINFO: StyleTable Description = X ID =100
-----------------------
class OrgWithLoginAndStyle {
/* Note use Query that
JOINS the Orgtable with the Login table
and JOINS the Orgtable with the Style table
*/
@Embedded
OrgTable orgTable;
@Embedded
LoginOptionsTable loginOptionsTable;
@Embedded
StyleTable styleTable;
}
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
class OrganizationWithLoginOptionsAndWithStyles {
@Embedded
OrgTable orgTable;
@Relation(entity = LoginOptionsTable.class,parentColumn = "loginOptionsId",entityColumn = "loginOpnId")
List<LoginOptionsTable> loginOptionsTables;
@Relation(entity = StyleTable.class,parentColumn = "stId",entityColumn = "styleId")
List<StyleTable> styleTables;
}
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Entity(foreignKeys = {@ForeignKey(entity = StyleTable.class, parentColumns =
"styleId", childColumns = "stId"),
@ForeignKey(entity = LoginOptionsTable.class, parentColumns =
"loginOpnId", childColumns = "loginOptionsId")
})
@Dao
public interface OrgDAO {
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Insert
long insertStyle(StyleTable styleTable);
@Insert
long insertLoginOptions(LoginOptionsTable loginOptionsTable);
}
public class MainActivity extends AppCompatActivity {
OrgLoginStyleDatabase db;
OrgDAO dao;
public static final String TAG = "OLSINFO";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Room.databaseBuilder(this,OrgLoginStyleDatabase.class,"orgloginoptionsstyle.db")
.allowMainThreadQueries()
.build();
dao = db.getOrgDao();
StyleTable s1 = new StyleTable();
s1.bannerBackgroundColor = "X";
s1.bannerTextColor = "X";
s1.baseTextSize = 20;
s1.bodyBackgroundColor = "X";
s1.bodyTextColor = "X";
s1.buttonBackgroundColor = "X";
s1.buttonTextColor = "X";
s1.htmlWrapper = "X";
s1.navigationBackgroundColor = "X";
s1.navigationTextColor = "X";
s1.styleId = 100;
s1.topBarBackgroundColor = "X";
s1.topBarLabel = "X";
s1.topBarTextColor = "X";
long s1Id = dao.insertStyle(s1);
LoginOptionsTable l1 = new LoginOptionsTable();
l1.allowedEmailDomain = "Y";
l1.authorizationEndpointUri = "Y";
l1.clientId = "Y";
l1.clientSecret = "Y";
l1.description = "Y";
l1.loginOpnId = 1000;
l1.name = "Y";
l1.nonce = "Y";
l1.redirectUri = "Y";
l1.restrictedEmailDomain = "Y";
l1.state = "Y";
l1.title = "Y";
l1.url = "Y";
long l1Id = dao.insertLoginOptions(l1);
OrgTable o1 = new OrgTable();
o1.description = "Z";
o1.id = 10000;
o1.loginOptionsId = l1Id;
o1.stId = s1Id;
dao.insertOrg(o1);
List<OrgTable> orgTableList = dao.getOrganizations();
for(OrgTable o: orgTableList) {
logOrgTable(o,"FROM getOrganizations -> ");
}
List<OrganizationWithLoginOptionsAndWithStyles> organizationsLoginsAndStylesList = dao.getOrganizationsLoginsAndStyles();
for(OrganizationWithLoginOptionsAndWithStyles owloaws: organizationsLoginsAndStylesList) {
logOrgTable(owloaws.orgTable,"FROM (@Relations) getOrganizationsLoginsAndStyles -> ");
for(LoginOptionsTable lot: owloaws.loginOptionsTables) {
logLoginOptionsTable(lot,"\t");
}
for(StyleTable s: owloaws.styleTables) {
logStyleTable(s,"\t");
}
}
List<OrgWithLoginAndStyle> owlas = dao.getOrganizationLoginAndStyle();
for(OrgWithLoginAndStyle o: owlas) {
logOrgTable(o.orgTable,"FROM (@Embeddeds) getOrganizationLoginAndStyle -> ");
logLoginOptionsTable(o.loginOptionsTable,"\t");
logStyleTable(o.styleTable,"\t");
}
}
private void logOrgTable(OrgTable o,String preamble) {
Log.d(TAG,preamble + "OrgTable Description = " + o.description + " ID = " + o.id);
}
private void logStyleTable(StyleTable s, String preamble) {
Log.d(TAG,preamble + "StyleTable Description = " + s.topBarTextColor + " ID =" + s.styleId);
}
private void logLoginOptionsTable(LoginOptionsTable l, String preamble) {
Log.d(TAG,preamble + "LoginOptionsTable Description = " + l.description + " ID = " + l.loginOpnId);
}
}
2021-04-12 21:51:50.981 D/OLSINFO: FROM getOrganizations -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: FROM (@Relations) getOrganizationsLoginsAndStyles -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.987 D/OLSINFO: StyleTable Description = X ID =100
2021-04-12 21:51:50.989 D/OLSINFO: FROM (@Embeddeds) getOrganizationLoginAndStyle -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.989 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.989 D/OLSINFO: StyleTable Description = X ID =100
-----------------------
class OrgWithLoginAndStyle {
/* Note use Query that
JOINS the Orgtable with the Login table
and JOINS the Orgtable with the Style table
*/
@Embedded
OrgTable orgTable;
@Embedded
LoginOptionsTable loginOptionsTable;
@Embedded
StyleTable styleTable;
}
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
class OrganizationWithLoginOptionsAndWithStyles {
@Embedded
OrgTable orgTable;
@Relation(entity = LoginOptionsTable.class,parentColumn = "loginOptionsId",entityColumn = "loginOpnId")
List<LoginOptionsTable> loginOptionsTables;
@Relation(entity = StyleTable.class,parentColumn = "stId",entityColumn = "styleId")
List<StyleTable> styleTables;
}
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Entity(foreignKeys = {@ForeignKey(entity = StyleTable.class, parentColumns =
"styleId", childColumns = "stId"),
@ForeignKey(entity = LoginOptionsTable.class, parentColumns =
"loginOpnId", childColumns = "loginOptionsId")
})
@Dao
public interface OrgDAO {
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Insert
long insertStyle(StyleTable styleTable);
@Insert
long insertLoginOptions(LoginOptionsTable loginOptionsTable);
}
public class MainActivity extends AppCompatActivity {
OrgLoginStyleDatabase db;
OrgDAO dao;
public static final String TAG = "OLSINFO";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Room.databaseBuilder(this,OrgLoginStyleDatabase.class,"orgloginoptionsstyle.db")
.allowMainThreadQueries()
.build();
dao = db.getOrgDao();
StyleTable s1 = new StyleTable();
s1.bannerBackgroundColor = "X";
s1.bannerTextColor = "X";
s1.baseTextSize = 20;
s1.bodyBackgroundColor = "X";
s1.bodyTextColor = "X";
s1.buttonBackgroundColor = "X";
s1.buttonTextColor = "X";
s1.htmlWrapper = "X";
s1.navigationBackgroundColor = "X";
s1.navigationTextColor = "X";
s1.styleId = 100;
s1.topBarBackgroundColor = "X";
s1.topBarLabel = "X";
s1.topBarTextColor = "X";
long s1Id = dao.insertStyle(s1);
LoginOptionsTable l1 = new LoginOptionsTable();
l1.allowedEmailDomain = "Y";
l1.authorizationEndpointUri = "Y";
l1.clientId = "Y";
l1.clientSecret = "Y";
l1.description = "Y";
l1.loginOpnId = 1000;
l1.name = "Y";
l1.nonce = "Y";
l1.redirectUri = "Y";
l1.restrictedEmailDomain = "Y";
l1.state = "Y";
l1.title = "Y";
l1.url = "Y";
long l1Id = dao.insertLoginOptions(l1);
OrgTable o1 = new OrgTable();
o1.description = "Z";
o1.id = 10000;
o1.loginOptionsId = l1Id;
o1.stId = s1Id;
dao.insertOrg(o1);
List<OrgTable> orgTableList = dao.getOrganizations();
for(OrgTable o: orgTableList) {
logOrgTable(o,"FROM getOrganizations -> ");
}
List<OrganizationWithLoginOptionsAndWithStyles> organizationsLoginsAndStylesList = dao.getOrganizationsLoginsAndStyles();
for(OrganizationWithLoginOptionsAndWithStyles owloaws: organizationsLoginsAndStylesList) {
logOrgTable(owloaws.orgTable,"FROM (@Relations) getOrganizationsLoginsAndStyles -> ");
for(LoginOptionsTable lot: owloaws.loginOptionsTables) {
logLoginOptionsTable(lot,"\t");
}
for(StyleTable s: owloaws.styleTables) {
logStyleTable(s,"\t");
}
}
List<OrgWithLoginAndStyle> owlas = dao.getOrganizationLoginAndStyle();
for(OrgWithLoginAndStyle o: owlas) {
logOrgTable(o.orgTable,"FROM (@Embeddeds) getOrganizationLoginAndStyle -> ");
logLoginOptionsTable(o.loginOptionsTable,"\t");
logStyleTable(o.styleTable,"\t");
}
}
private void logOrgTable(OrgTable o,String preamble) {
Log.d(TAG,preamble + "OrgTable Description = " + o.description + " ID = " + o.id);
}
private void logStyleTable(StyleTable s, String preamble) {
Log.d(TAG,preamble + "StyleTable Description = " + s.topBarTextColor + " ID =" + s.styleId);
}
private void logLoginOptionsTable(LoginOptionsTable l, String preamble) {
Log.d(TAG,preamble + "LoginOptionsTable Description = " + l.description + " ID = " + l.loginOpnId);
}
}
2021-04-12 21:51:50.981 D/OLSINFO: FROM getOrganizations -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: FROM (@Relations) getOrganizationsLoginsAndStyles -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.987 D/OLSINFO: StyleTable Description = X ID =100
2021-04-12 21:51:50.989 D/OLSINFO: FROM (@Embeddeds) getOrganizationLoginAndStyle -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.989 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.989 D/OLSINFO: StyleTable Description = X ID =100
-----------------------
class OrgWithLoginAndStyle {
/* Note use Query that
JOINS the Orgtable with the Login table
and JOINS the Orgtable with the Style table
*/
@Embedded
OrgTable orgTable;
@Embedded
LoginOptionsTable loginOptionsTable;
@Embedded
StyleTable styleTable;
}
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
class OrganizationWithLoginOptionsAndWithStyles {
@Embedded
OrgTable orgTable;
@Relation(entity = LoginOptionsTable.class,parentColumn = "loginOptionsId",entityColumn = "loginOpnId")
List<LoginOptionsTable> loginOptionsTables;
@Relation(entity = StyleTable.class,parentColumn = "stId",entityColumn = "styleId")
List<StyleTable> styleTables;
}
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Entity(foreignKeys = {@ForeignKey(entity = StyleTable.class, parentColumns =
"styleId", childColumns = "stId"),
@ForeignKey(entity = LoginOptionsTable.class, parentColumns =
"loginOpnId", childColumns = "loginOptionsId")
})
@Dao
public interface OrgDAO {
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Insert
long insertStyle(StyleTable styleTable);
@Insert
long insertLoginOptions(LoginOptionsTable loginOptionsTable);
}
public class MainActivity extends AppCompatActivity {
OrgLoginStyleDatabase db;
OrgDAO dao;
public static final String TAG = "OLSINFO";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Room.databaseBuilder(this,OrgLoginStyleDatabase.class,"orgloginoptionsstyle.db")
.allowMainThreadQueries()
.build();
dao = db.getOrgDao();
StyleTable s1 = new StyleTable();
s1.bannerBackgroundColor = "X";
s1.bannerTextColor = "X";
s1.baseTextSize = 20;
s1.bodyBackgroundColor = "X";
s1.bodyTextColor = "X";
s1.buttonBackgroundColor = "X";
s1.buttonTextColor = "X";
s1.htmlWrapper = "X";
s1.navigationBackgroundColor = "X";
s1.navigationTextColor = "X";
s1.styleId = 100;
s1.topBarBackgroundColor = "X";
s1.topBarLabel = "X";
s1.topBarTextColor = "X";
long s1Id = dao.insertStyle(s1);
LoginOptionsTable l1 = new LoginOptionsTable();
l1.allowedEmailDomain = "Y";
l1.authorizationEndpointUri = "Y";
l1.clientId = "Y";
l1.clientSecret = "Y";
l1.description = "Y";
l1.loginOpnId = 1000;
l1.name = "Y";
l1.nonce = "Y";
l1.redirectUri = "Y";
l1.restrictedEmailDomain = "Y";
l1.state = "Y";
l1.title = "Y";
l1.url = "Y";
long l1Id = dao.insertLoginOptions(l1);
OrgTable o1 = new OrgTable();
o1.description = "Z";
o1.id = 10000;
o1.loginOptionsId = l1Id;
o1.stId = s1Id;
dao.insertOrg(o1);
List<OrgTable> orgTableList = dao.getOrganizations();
for(OrgTable o: orgTableList) {
logOrgTable(o,"FROM getOrganizations -> ");
}
List<OrganizationWithLoginOptionsAndWithStyles> organizationsLoginsAndStylesList = dao.getOrganizationsLoginsAndStyles();
for(OrganizationWithLoginOptionsAndWithStyles owloaws: organizationsLoginsAndStylesList) {
logOrgTable(owloaws.orgTable,"FROM (@Relations) getOrganizationsLoginsAndStyles -> ");
for(LoginOptionsTable lot: owloaws.loginOptionsTables) {
logLoginOptionsTable(lot,"\t");
}
for(StyleTable s: owloaws.styleTables) {
logStyleTable(s,"\t");
}
}
List<OrgWithLoginAndStyle> owlas = dao.getOrganizationLoginAndStyle();
for(OrgWithLoginAndStyle o: owlas) {
logOrgTable(o.orgTable,"FROM (@Embeddeds) getOrganizationLoginAndStyle -> ");
logLoginOptionsTable(o.loginOptionsTable,"\t");
logStyleTable(o.styleTable,"\t");
}
}
private void logOrgTable(OrgTable o,String preamble) {
Log.d(TAG,preamble + "OrgTable Description = " + o.description + " ID = " + o.id);
}
private void logStyleTable(StyleTable s, String preamble) {
Log.d(TAG,preamble + "StyleTable Description = " + s.topBarTextColor + " ID =" + s.styleId);
}
private void logLoginOptionsTable(LoginOptionsTable l, String preamble) {
Log.d(TAG,preamble + "LoginOptionsTable Description = " + l.description + " ID = " + l.loginOpnId);
}
}
2021-04-12 21:51:50.981 D/OLSINFO: FROM getOrganizations -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: FROM (@Relations) getOrganizationsLoginsAndStyles -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.987 D/OLSINFO: StyleTable Description = X ID =100
2021-04-12 21:51:50.989 D/OLSINFO: FROM (@Embeddeds) getOrganizationLoginAndStyle -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.989 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.989 D/OLSINFO: StyleTable Description = X ID =100
-----------------------
class OrgWithLoginAndStyle {
/* Note use Query that
JOINS the Orgtable with the Login table
and JOINS the Orgtable with the Style table
*/
@Embedded
OrgTable orgTable;
@Embedded
LoginOptionsTable loginOptionsTable;
@Embedded
StyleTable styleTable;
}
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
class OrganizationWithLoginOptionsAndWithStyles {
@Embedded
OrgTable orgTable;
@Relation(entity = LoginOptionsTable.class,parentColumn = "loginOptionsId",entityColumn = "loginOpnId")
List<LoginOptionsTable> loginOptionsTables;
@Relation(entity = StyleTable.class,parentColumn = "stId",entityColumn = "styleId")
List<StyleTable> styleTables;
}
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Entity(foreignKeys = {@ForeignKey(entity = StyleTable.class, parentColumns =
"styleId", childColumns = "stId"),
@ForeignKey(entity = LoginOptionsTable.class, parentColumns =
"loginOpnId", childColumns = "loginOptionsId")
})
@Dao
public interface OrgDAO {
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Insert
long insertStyle(StyleTable styleTable);
@Insert
long insertLoginOptions(LoginOptionsTable loginOptionsTable);
}
public class MainActivity extends AppCompatActivity {
OrgLoginStyleDatabase db;
OrgDAO dao;
public static final String TAG = "OLSINFO";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Room.databaseBuilder(this,OrgLoginStyleDatabase.class,"orgloginoptionsstyle.db")
.allowMainThreadQueries()
.build();
dao = db.getOrgDao();
StyleTable s1 = new StyleTable();
s1.bannerBackgroundColor = "X";
s1.bannerTextColor = "X";
s1.baseTextSize = 20;
s1.bodyBackgroundColor = "X";
s1.bodyTextColor = "X";
s1.buttonBackgroundColor = "X";
s1.buttonTextColor = "X";
s1.htmlWrapper = "X";
s1.navigationBackgroundColor = "X";
s1.navigationTextColor = "X";
s1.styleId = 100;
s1.topBarBackgroundColor = "X";
s1.topBarLabel = "X";
s1.topBarTextColor = "X";
long s1Id = dao.insertStyle(s1);
LoginOptionsTable l1 = new LoginOptionsTable();
l1.allowedEmailDomain = "Y";
l1.authorizationEndpointUri = "Y";
l1.clientId = "Y";
l1.clientSecret = "Y";
l1.description = "Y";
l1.loginOpnId = 1000;
l1.name = "Y";
l1.nonce = "Y";
l1.redirectUri = "Y";
l1.restrictedEmailDomain = "Y";
l1.state = "Y";
l1.title = "Y";
l1.url = "Y";
long l1Id = dao.insertLoginOptions(l1);
OrgTable o1 = new OrgTable();
o1.description = "Z";
o1.id = 10000;
o1.loginOptionsId = l1Id;
o1.stId = s1Id;
dao.insertOrg(o1);
List<OrgTable> orgTableList = dao.getOrganizations();
for(OrgTable o: orgTableList) {
logOrgTable(o,"FROM getOrganizations -> ");
}
List<OrganizationWithLoginOptionsAndWithStyles> organizationsLoginsAndStylesList = dao.getOrganizationsLoginsAndStyles();
for(OrganizationWithLoginOptionsAndWithStyles owloaws: organizationsLoginsAndStylesList) {
logOrgTable(owloaws.orgTable,"FROM (@Relations) getOrganizationsLoginsAndStyles -> ");
for(LoginOptionsTable lot: owloaws.loginOptionsTables) {
logLoginOptionsTable(lot,"\t");
}
for(StyleTable s: owloaws.styleTables) {
logStyleTable(s,"\t");
}
}
List<OrgWithLoginAndStyle> owlas = dao.getOrganizationLoginAndStyle();
for(OrgWithLoginAndStyle o: owlas) {
logOrgTable(o.orgTable,"FROM (@Embeddeds) getOrganizationLoginAndStyle -> ");
logLoginOptionsTable(o.loginOptionsTable,"\t");
logStyleTable(o.styleTable,"\t");
}
}
private void logOrgTable(OrgTable o,String preamble) {
Log.d(TAG,preamble + "OrgTable Description = " + o.description + " ID = " + o.id);
}
private void logStyleTable(StyleTable s, String preamble) {
Log.d(TAG,preamble + "StyleTable Description = " + s.topBarTextColor + " ID =" + s.styleId);
}
private void logLoginOptionsTable(LoginOptionsTable l, String preamble) {
Log.d(TAG,preamble + "LoginOptionsTable Description = " + l.description + " ID = " + l.loginOpnId);
}
}
2021-04-12 21:51:50.981 D/OLSINFO: FROM getOrganizations -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: FROM (@Relations) getOrganizationsLoginsAndStyles -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.987 D/OLSINFO: StyleTable Description = X ID =100
2021-04-12 21:51:50.989 D/OLSINFO: FROM (@Embeddeds) getOrganizationLoginAndStyle -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.989 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.989 D/OLSINFO: StyleTable Description = X ID =100
-----------------------
class OrgWithLoginAndStyle {
/* Note use Query that
JOINS the Orgtable with the Login table
and JOINS the Orgtable with the Style table
*/
@Embedded
OrgTable orgTable;
@Embedded
LoginOptionsTable loginOptionsTable;
@Embedded
StyleTable styleTable;
}
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
class OrganizationWithLoginOptionsAndWithStyles {
@Embedded
OrgTable orgTable;
@Relation(entity = LoginOptionsTable.class,parentColumn = "loginOptionsId",entityColumn = "loginOpnId")
List<LoginOptionsTable> loginOptionsTables;
@Relation(entity = StyleTable.class,parentColumn = "stId",entityColumn = "styleId")
List<StyleTable> styleTables;
}
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Entity(foreignKeys = {@ForeignKey(entity = StyleTable.class, parentColumns =
"styleId", childColumns = "stId"),
@ForeignKey(entity = LoginOptionsTable.class, parentColumns =
"loginOpnId", childColumns = "loginOptionsId")
})
@Dao
public interface OrgDAO {
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Insert
long insertStyle(StyleTable styleTable);
@Insert
long insertLoginOptions(LoginOptionsTable loginOptionsTable);
}
public class MainActivity extends AppCompatActivity {
OrgLoginStyleDatabase db;
OrgDAO dao;
public static final String TAG = "OLSINFO";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Room.databaseBuilder(this,OrgLoginStyleDatabase.class,"orgloginoptionsstyle.db")
.allowMainThreadQueries()
.build();
dao = db.getOrgDao();
StyleTable s1 = new StyleTable();
s1.bannerBackgroundColor = "X";
s1.bannerTextColor = "X";
s1.baseTextSize = 20;
s1.bodyBackgroundColor = "X";
s1.bodyTextColor = "X";
s1.buttonBackgroundColor = "X";
s1.buttonTextColor = "X";
s1.htmlWrapper = "X";
s1.navigationBackgroundColor = "X";
s1.navigationTextColor = "X";
s1.styleId = 100;
s1.topBarBackgroundColor = "X";
s1.topBarLabel = "X";
s1.topBarTextColor = "X";
long s1Id = dao.insertStyle(s1);
LoginOptionsTable l1 = new LoginOptionsTable();
l1.allowedEmailDomain = "Y";
l1.authorizationEndpointUri = "Y";
l1.clientId = "Y";
l1.clientSecret = "Y";
l1.description = "Y";
l1.loginOpnId = 1000;
l1.name = "Y";
l1.nonce = "Y";
l1.redirectUri = "Y";
l1.restrictedEmailDomain = "Y";
l1.state = "Y";
l1.title = "Y";
l1.url = "Y";
long l1Id = dao.insertLoginOptions(l1);
OrgTable o1 = new OrgTable();
o1.description = "Z";
o1.id = 10000;
o1.loginOptionsId = l1Id;
o1.stId = s1Id;
dao.insertOrg(o1);
List<OrgTable> orgTableList = dao.getOrganizations();
for(OrgTable o: orgTableList) {
logOrgTable(o,"FROM getOrganizations -> ");
}
List<OrganizationWithLoginOptionsAndWithStyles> organizationsLoginsAndStylesList = dao.getOrganizationsLoginsAndStyles();
for(OrganizationWithLoginOptionsAndWithStyles owloaws: organizationsLoginsAndStylesList) {
logOrgTable(owloaws.orgTable,"FROM (@Relations) getOrganizationsLoginsAndStyles -> ");
for(LoginOptionsTable lot: owloaws.loginOptionsTables) {
logLoginOptionsTable(lot,"\t");
}
for(StyleTable s: owloaws.styleTables) {
logStyleTable(s,"\t");
}
}
List<OrgWithLoginAndStyle> owlas = dao.getOrganizationLoginAndStyle();
for(OrgWithLoginAndStyle o: owlas) {
logOrgTable(o.orgTable,"FROM (@Embeddeds) getOrganizationLoginAndStyle -> ");
logLoginOptionsTable(o.loginOptionsTable,"\t");
logStyleTable(o.styleTable,"\t");
}
}
private void logOrgTable(OrgTable o,String preamble) {
Log.d(TAG,preamble + "OrgTable Description = " + o.description + " ID = " + o.id);
}
private void logStyleTable(StyleTable s, String preamble) {
Log.d(TAG,preamble + "StyleTable Description = " + s.topBarTextColor + " ID =" + s.styleId);
}
private void logLoginOptionsTable(LoginOptionsTable l, String preamble) {
Log.d(TAG,preamble + "LoginOptionsTable Description = " + l.description + " ID = " + l.loginOpnId);
}
}
2021-04-12 21:51:50.981 D/OLSINFO: FROM getOrganizations -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: FROM (@Relations) getOrganizationsLoginsAndStyles -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.987 D/OLSINFO: StyleTable Description = X ID =100
2021-04-12 21:51:50.989 D/OLSINFO: FROM (@Embeddeds) getOrganizationLoginAndStyle -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.989 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.989 D/OLSINFO: StyleTable Description = X ID =100
-----------------------
class OrgWithLoginAndStyle {
/* Note use Query that
JOINS the Orgtable with the Login table
and JOINS the Orgtable with the Style table
*/
@Embedded
OrgTable orgTable;
@Embedded
LoginOptionsTable loginOptionsTable;
@Embedded
StyleTable styleTable;
}
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
class OrganizationWithLoginOptionsAndWithStyles {
@Embedded
OrgTable orgTable;
@Relation(entity = LoginOptionsTable.class,parentColumn = "loginOptionsId",entityColumn = "loginOpnId")
List<LoginOptionsTable> loginOptionsTables;
@Relation(entity = StyleTable.class,parentColumn = "stId",entityColumn = "styleId")
List<StyleTable> styleTables;
}
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Entity(foreignKeys = {@ForeignKey(entity = StyleTable.class, parentColumns =
"styleId", childColumns = "stId"),
@ForeignKey(entity = LoginOptionsTable.class, parentColumns =
"loginOpnId", childColumns = "loginOptionsId")
})
@Dao
public interface OrgDAO {
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Insert
long insertStyle(StyleTable styleTable);
@Insert
long insertLoginOptions(LoginOptionsTable loginOptionsTable);
}
public class MainActivity extends AppCompatActivity {
OrgLoginStyleDatabase db;
OrgDAO dao;
public static final String TAG = "OLSINFO";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Room.databaseBuilder(this,OrgLoginStyleDatabase.class,"orgloginoptionsstyle.db")
.allowMainThreadQueries()
.build();
dao = db.getOrgDao();
StyleTable s1 = new StyleTable();
s1.bannerBackgroundColor = "X";
s1.bannerTextColor = "X";
s1.baseTextSize = 20;
s1.bodyBackgroundColor = "X";
s1.bodyTextColor = "X";
s1.buttonBackgroundColor = "X";
s1.buttonTextColor = "X";
s1.htmlWrapper = "X";
s1.navigationBackgroundColor = "X";
s1.navigationTextColor = "X";
s1.styleId = 100;
s1.topBarBackgroundColor = "X";
s1.topBarLabel = "X";
s1.topBarTextColor = "X";
long s1Id = dao.insertStyle(s1);
LoginOptionsTable l1 = new LoginOptionsTable();
l1.allowedEmailDomain = "Y";
l1.authorizationEndpointUri = "Y";
l1.clientId = "Y";
l1.clientSecret = "Y";
l1.description = "Y";
l1.loginOpnId = 1000;
l1.name = "Y";
l1.nonce = "Y";
l1.redirectUri = "Y";
l1.restrictedEmailDomain = "Y";
l1.state = "Y";
l1.title = "Y";
l1.url = "Y";
long l1Id = dao.insertLoginOptions(l1);
OrgTable o1 = new OrgTable();
o1.description = "Z";
o1.id = 10000;
o1.loginOptionsId = l1Id;
o1.stId = s1Id;
dao.insertOrg(o1);
List<OrgTable> orgTableList = dao.getOrganizations();
for(OrgTable o: orgTableList) {
logOrgTable(o,"FROM getOrganizations -> ");
}
List<OrganizationWithLoginOptionsAndWithStyles> organizationsLoginsAndStylesList = dao.getOrganizationsLoginsAndStyles();
for(OrganizationWithLoginOptionsAndWithStyles owloaws: organizationsLoginsAndStylesList) {
logOrgTable(owloaws.orgTable,"FROM (@Relations) getOrganizationsLoginsAndStyles -> ");
for(LoginOptionsTable lot: owloaws.loginOptionsTables) {
logLoginOptionsTable(lot,"\t");
}
for(StyleTable s: owloaws.styleTables) {
logStyleTable(s,"\t");
}
}
List<OrgWithLoginAndStyle> owlas = dao.getOrganizationLoginAndStyle();
for(OrgWithLoginAndStyle o: owlas) {
logOrgTable(o.orgTable,"FROM (@Embeddeds) getOrganizationLoginAndStyle -> ");
logLoginOptionsTable(o.loginOptionsTable,"\t");
logStyleTable(o.styleTable,"\t");
}
}
private void logOrgTable(OrgTable o,String preamble) {
Log.d(TAG,preamble + "OrgTable Description = " + o.description + " ID = " + o.id);
}
private void logStyleTable(StyleTable s, String preamble) {
Log.d(TAG,preamble + "StyleTable Description = " + s.topBarTextColor + " ID =" + s.styleId);
}
private void logLoginOptionsTable(LoginOptionsTable l, String preamble) {
Log.d(TAG,preamble + "LoginOptionsTable Description = " + l.description + " ID = " + l.loginOpnId);
}
}
2021-04-12 21:51:50.981 D/OLSINFO: FROM getOrganizations -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: FROM (@Relations) getOrganizationsLoginsAndStyles -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.987 D/OLSINFO: StyleTable Description = X ID =100
2021-04-12 21:51:50.989 D/OLSINFO: FROM (@Embeddeds) getOrganizationLoginAndStyle -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.989 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.989 D/OLSINFO: StyleTable Description = X ID =100
-----------------------
class OrgWithLoginAndStyle {
/* Note use Query that
JOINS the Orgtable with the Login table
and JOINS the Orgtable with the Style table
*/
@Embedded
OrgTable orgTable;
@Embedded
LoginOptionsTable loginOptionsTable;
@Embedded
StyleTable styleTable;
}
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
class OrganizationWithLoginOptionsAndWithStyles {
@Embedded
OrgTable orgTable;
@Relation(entity = LoginOptionsTable.class,parentColumn = "loginOptionsId",entityColumn = "loginOpnId")
List<LoginOptionsTable> loginOptionsTables;
@Relation(entity = StyleTable.class,parentColumn = "stId",entityColumn = "styleId")
List<StyleTable> styleTables;
}
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Entity(foreignKeys = {@ForeignKey(entity = StyleTable.class, parentColumns =
"styleId", childColumns = "stId"),
@ForeignKey(entity = LoginOptionsTable.class, parentColumns =
"loginOpnId", childColumns = "loginOptionsId")
})
@Dao
public interface OrgDAO {
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Insert
long insertStyle(StyleTable styleTable);
@Insert
long insertLoginOptions(LoginOptionsTable loginOptionsTable);
}
public class MainActivity extends AppCompatActivity {
OrgLoginStyleDatabase db;
OrgDAO dao;
public static final String TAG = "OLSINFO";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Room.databaseBuilder(this,OrgLoginStyleDatabase.class,"orgloginoptionsstyle.db")
.allowMainThreadQueries()
.build();
dao = db.getOrgDao();
StyleTable s1 = new StyleTable();
s1.bannerBackgroundColor = "X";
s1.bannerTextColor = "X";
s1.baseTextSize = 20;
s1.bodyBackgroundColor = "X";
s1.bodyTextColor = "X";
s1.buttonBackgroundColor = "X";
s1.buttonTextColor = "X";
s1.htmlWrapper = "X";
s1.navigationBackgroundColor = "X";
s1.navigationTextColor = "X";
s1.styleId = 100;
s1.topBarBackgroundColor = "X";
s1.topBarLabel = "X";
s1.topBarTextColor = "X";
long s1Id = dao.insertStyle(s1);
LoginOptionsTable l1 = new LoginOptionsTable();
l1.allowedEmailDomain = "Y";
l1.authorizationEndpointUri = "Y";
l1.clientId = "Y";
l1.clientSecret = "Y";
l1.description = "Y";
l1.loginOpnId = 1000;
l1.name = "Y";
l1.nonce = "Y";
l1.redirectUri = "Y";
l1.restrictedEmailDomain = "Y";
l1.state = "Y";
l1.title = "Y";
l1.url = "Y";
long l1Id = dao.insertLoginOptions(l1);
OrgTable o1 = new OrgTable();
o1.description = "Z";
o1.id = 10000;
o1.loginOptionsId = l1Id;
o1.stId = s1Id;
dao.insertOrg(o1);
List<OrgTable> orgTableList = dao.getOrganizations();
for(OrgTable o: orgTableList) {
logOrgTable(o,"FROM getOrganizations -> ");
}
List<OrganizationWithLoginOptionsAndWithStyles> organizationsLoginsAndStylesList = dao.getOrganizationsLoginsAndStyles();
for(OrganizationWithLoginOptionsAndWithStyles owloaws: organizationsLoginsAndStylesList) {
logOrgTable(owloaws.orgTable,"FROM (@Relations) getOrganizationsLoginsAndStyles -> ");
for(LoginOptionsTable lot: owloaws.loginOptionsTables) {
logLoginOptionsTable(lot,"\t");
}
for(StyleTable s: owloaws.styleTables) {
logStyleTable(s,"\t");
}
}
List<OrgWithLoginAndStyle> owlas = dao.getOrganizationLoginAndStyle();
for(OrgWithLoginAndStyle o: owlas) {
logOrgTable(o.orgTable,"FROM (@Embeddeds) getOrganizationLoginAndStyle -> ");
logLoginOptionsTable(o.loginOptionsTable,"\t");
logStyleTable(o.styleTable,"\t");
}
}
private void logOrgTable(OrgTable o,String preamble) {
Log.d(TAG,preamble + "OrgTable Description = " + o.description + " ID = " + o.id);
}
private void logStyleTable(StyleTable s, String preamble) {
Log.d(TAG,preamble + "StyleTable Description = " + s.topBarTextColor + " ID =" + s.styleId);
}
private void logLoginOptionsTable(LoginOptionsTable l, String preamble) {
Log.d(TAG,preamble + "LoginOptionsTable Description = " + l.description + " ID = " + l.loginOpnId);
}
}
2021-04-12 21:51:50.981 D/OLSINFO: FROM getOrganizations -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: FROM (@Relations) getOrganizationsLoginsAndStyles -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.987 D/OLSINFO: StyleTable Description = X ID =100
2021-04-12 21:51:50.989 D/OLSINFO: FROM (@Embeddeds) getOrganizationLoginAndStyle -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.989 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.989 D/OLSINFO: StyleTable Description = X ID =100
-----------------------
class OrgWithLoginAndStyle {
/* Note use Query that
JOINS the Orgtable with the Login table
and JOINS the Orgtable with the Style table
*/
@Embedded
OrgTable orgTable;
@Embedded
LoginOptionsTable loginOptionsTable;
@Embedded
StyleTable styleTable;
}
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
class OrganizationWithLoginOptionsAndWithStyles {
@Embedded
OrgTable orgTable;
@Relation(entity = LoginOptionsTable.class,parentColumn = "loginOptionsId",entityColumn = "loginOpnId")
List<LoginOptionsTable> loginOptionsTables;
@Relation(entity = StyleTable.class,parentColumn = "stId",entityColumn = "styleId")
List<StyleTable> styleTables;
}
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Entity(foreignKeys = {@ForeignKey(entity = StyleTable.class, parentColumns =
"styleId", childColumns = "stId"),
@ForeignKey(entity = LoginOptionsTable.class, parentColumns =
"loginOpnId", childColumns = "loginOptionsId")
})
@Dao
public interface OrgDAO {
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Insert
long insertStyle(StyleTable styleTable);
@Insert
long insertLoginOptions(LoginOptionsTable loginOptionsTable);
}
public class MainActivity extends AppCompatActivity {
OrgLoginStyleDatabase db;
OrgDAO dao;
public static final String TAG = "OLSINFO";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Room.databaseBuilder(this,OrgLoginStyleDatabase.class,"orgloginoptionsstyle.db")
.allowMainThreadQueries()
.build();
dao = db.getOrgDao();
StyleTable s1 = new StyleTable();
s1.bannerBackgroundColor = "X";
s1.bannerTextColor = "X";
s1.baseTextSize = 20;
s1.bodyBackgroundColor = "X";
s1.bodyTextColor = "X";
s1.buttonBackgroundColor = "X";
s1.buttonTextColor = "X";
s1.htmlWrapper = "X";
s1.navigationBackgroundColor = "X";
s1.navigationTextColor = "X";
s1.styleId = 100;
s1.topBarBackgroundColor = "X";
s1.topBarLabel = "X";
s1.topBarTextColor = "X";
long s1Id = dao.insertStyle(s1);
LoginOptionsTable l1 = new LoginOptionsTable();
l1.allowedEmailDomain = "Y";
l1.authorizationEndpointUri = "Y";
l1.clientId = "Y";
l1.clientSecret = "Y";
l1.description = "Y";
l1.loginOpnId = 1000;
l1.name = "Y";
l1.nonce = "Y";
l1.redirectUri = "Y";
l1.restrictedEmailDomain = "Y";
l1.state = "Y";
l1.title = "Y";
l1.url = "Y";
long l1Id = dao.insertLoginOptions(l1);
OrgTable o1 = new OrgTable();
o1.description = "Z";
o1.id = 10000;
o1.loginOptionsId = l1Id;
o1.stId = s1Id;
dao.insertOrg(o1);
List<OrgTable> orgTableList = dao.getOrganizations();
for(OrgTable o: orgTableList) {
logOrgTable(o,"FROM getOrganizations -> ");
}
List<OrganizationWithLoginOptionsAndWithStyles> organizationsLoginsAndStylesList = dao.getOrganizationsLoginsAndStyles();
for(OrganizationWithLoginOptionsAndWithStyles owloaws: organizationsLoginsAndStylesList) {
logOrgTable(owloaws.orgTable,"FROM (@Relations) getOrganizationsLoginsAndStyles -> ");
for(LoginOptionsTable lot: owloaws.loginOptionsTables) {
logLoginOptionsTable(lot,"\t");
}
for(StyleTable s: owloaws.styleTables) {
logStyleTable(s,"\t");
}
}
List<OrgWithLoginAndStyle> owlas = dao.getOrganizationLoginAndStyle();
for(OrgWithLoginAndStyle o: owlas) {
logOrgTable(o.orgTable,"FROM (@Embeddeds) getOrganizationLoginAndStyle -> ");
logLoginOptionsTable(o.loginOptionsTable,"\t");
logStyleTable(o.styleTable,"\t");
}
}
private void logOrgTable(OrgTable o,String preamble) {
Log.d(TAG,preamble + "OrgTable Description = " + o.description + " ID = " + o.id);
}
private void logStyleTable(StyleTable s, String preamble) {
Log.d(TAG,preamble + "StyleTable Description = " + s.topBarTextColor + " ID =" + s.styleId);
}
private void logLoginOptionsTable(LoginOptionsTable l, String preamble) {
Log.d(TAG,preamble + "LoginOptionsTable Description = " + l.description + " ID = " + l.loginOpnId);
}
}
2021-04-12 21:51:50.981 D/OLSINFO: FROM getOrganizations -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: FROM (@Relations) getOrganizationsLoginsAndStyles -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.987 D/OLSINFO: StyleTable Description = X ID =100
2021-04-12 21:51:50.989 D/OLSINFO: FROM (@Embeddeds) getOrganizationLoginAndStyle -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.989 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.989 D/OLSINFO: StyleTable Description = X ID =100
-----------------------
class OrgWithLoginAndStyle {
/* Note use Query that
JOINS the Orgtable with the Login table
and JOINS the Orgtable with the Style table
*/
@Embedded
OrgTable orgTable;
@Embedded
LoginOptionsTable loginOptionsTable;
@Embedded
StyleTable styleTable;
}
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
class OrganizationWithLoginOptionsAndWithStyles {
@Embedded
OrgTable orgTable;
@Relation(entity = LoginOptionsTable.class,parentColumn = "loginOptionsId",entityColumn = "loginOpnId")
List<LoginOptionsTable> loginOptionsTables;
@Relation(entity = StyleTable.class,parentColumn = "stId",entityColumn = "styleId")
List<StyleTable> styleTables;
}
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Entity(foreignKeys = {@ForeignKey(entity = StyleTable.class, parentColumns =
"styleId", childColumns = "stId"),
@ForeignKey(entity = LoginOptionsTable.class, parentColumns =
"loginOpnId", childColumns = "loginOptionsId")
})
@Dao
public interface OrgDAO {
@Query("SELECT * FROM OrgTable")
//OrgTable getOrganization(); /* <<<<<<<<<< WRONG should be a List */
List<OrgTable> getOrganizations();
@Query("SELECT * FROM OrgTable " +
"JOIN StyleTable ON StyleTable.styleId = OrgTable.stId " +
"JOIN LoginOptionsTable ON LoginOptionsTable.loginOpnId = OrgTable.loginOptionsId")
List<OrgWithLoginAndStyle> getOrganizationLoginAndStyle();
@Transaction
@Query("SELECT * FROM OrgTable")
List<OrganizationWithLoginOptionsAndWithStyles> getOrganizationsLoginsAndStyles();
@Insert
//void insertOrg(OrgTable org)
long insertOrg(OrgTable org); /* <<<<<<<<<< might as well allow the id of the inserted row to be obtained */
@Insert
long insertStyle(StyleTable styleTable);
@Insert
long insertLoginOptions(LoginOptionsTable loginOptionsTable);
}
public class MainActivity extends AppCompatActivity {
OrgLoginStyleDatabase db;
OrgDAO dao;
public static final String TAG = "OLSINFO";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = Room.databaseBuilder(this,OrgLoginStyleDatabase.class,"orgloginoptionsstyle.db")
.allowMainThreadQueries()
.build();
dao = db.getOrgDao();
StyleTable s1 = new StyleTable();
s1.bannerBackgroundColor = "X";
s1.bannerTextColor = "X";
s1.baseTextSize = 20;
s1.bodyBackgroundColor = "X";
s1.bodyTextColor = "X";
s1.buttonBackgroundColor = "X";
s1.buttonTextColor = "X";
s1.htmlWrapper = "X";
s1.navigationBackgroundColor = "X";
s1.navigationTextColor = "X";
s1.styleId = 100;
s1.topBarBackgroundColor = "X";
s1.topBarLabel = "X";
s1.topBarTextColor = "X";
long s1Id = dao.insertStyle(s1);
LoginOptionsTable l1 = new LoginOptionsTable();
l1.allowedEmailDomain = "Y";
l1.authorizationEndpointUri = "Y";
l1.clientId = "Y";
l1.clientSecret = "Y";
l1.description = "Y";
l1.loginOpnId = 1000;
l1.name = "Y";
l1.nonce = "Y";
l1.redirectUri = "Y";
l1.restrictedEmailDomain = "Y";
l1.state = "Y";
l1.title = "Y";
l1.url = "Y";
long l1Id = dao.insertLoginOptions(l1);
OrgTable o1 = new OrgTable();
o1.description = "Z";
o1.id = 10000;
o1.loginOptionsId = l1Id;
o1.stId = s1Id;
dao.insertOrg(o1);
List<OrgTable> orgTableList = dao.getOrganizations();
for(OrgTable o: orgTableList) {
logOrgTable(o,"FROM getOrganizations -> ");
}
List<OrganizationWithLoginOptionsAndWithStyles> organizationsLoginsAndStylesList = dao.getOrganizationsLoginsAndStyles();
for(OrganizationWithLoginOptionsAndWithStyles owloaws: organizationsLoginsAndStylesList) {
logOrgTable(owloaws.orgTable,"FROM (@Relations) getOrganizationsLoginsAndStyles -> ");
for(LoginOptionsTable lot: owloaws.loginOptionsTables) {
logLoginOptionsTable(lot,"\t");
}
for(StyleTable s: owloaws.styleTables) {
logStyleTable(s,"\t");
}
}
List<OrgWithLoginAndStyle> owlas = dao.getOrganizationLoginAndStyle();
for(OrgWithLoginAndStyle o: owlas) {
logOrgTable(o.orgTable,"FROM (@Embeddeds) getOrganizationLoginAndStyle -> ");
logLoginOptionsTable(o.loginOptionsTable,"\t");
logStyleTable(o.styleTable,"\t");
}
}
private void logOrgTable(OrgTable o,String preamble) {
Log.d(TAG,preamble + "OrgTable Description = " + o.description + " ID = " + o.id);
}
private void logStyleTable(StyleTable s, String preamble) {
Log.d(TAG,preamble + "StyleTable Description = " + s.topBarTextColor + " ID =" + s.styleId);
}
private void logLoginOptionsTable(LoginOptionsTable l, String preamble) {
Log.d(TAG,preamble + "LoginOptionsTable Description = " + l.description + " ID = " + l.loginOpnId);
}
}
2021-04-12 21:51:50.981 D/OLSINFO: FROM getOrganizations -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: FROM (@Relations) getOrganizationsLoginsAndStyles -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.987 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.987 D/OLSINFO: StyleTable Description = X ID =100
2021-04-12 21:51:50.989 D/OLSINFO: FROM (@Embeddeds) getOrganizationLoginAndStyle -> OrgTable Description = Z ID = 10000
2021-04-12 21:51:50.989 D/OLSINFO: LoginOptionsTable Description = Y ID = 1000
2021-04-12 21:51:50.989 D/OLSINFO: StyleTable Description = X ID =100
QUESTION
Retrofit Body isn't showing desired response from Nested JSON
Asked 2022-Mar-27 at 00:02I've been trying to connect an Android App to the Fitbit API using Retrofit however I'm struggling with getting a connection to a JSON with a nested user section. I've managed to get the classes set up however get Body: com.example.myapplication.User@6fe68c1 when requesting the body back.
Whilst learning about Retrofit I've had no problems with using however this seems to be different because of the "user" in the JSON.
Shortened JSON I'm working from
{
"user": {
"age": 23,
"avatar": "https://static0.fitbit.com/images/profile/defaultProfile_100.png",
"averageDailySteps": 2673,
"dateOfBirth": "1999-01-25",
"displayName": "Name.",
"features": {
"exerciseGoal": true
},
"fullName": "Full Name",
"gender": "MALE",
"glucoseUnit": "METRIC",
"height": 180.3,
"memberSince": "2022-02-28",
"startDayOfWeek": "MONDAY",
"strideLengthRunning": 123.10000000000001,
"weight": 72.5,
}
}
Fitbit Class
imports
@Generated("jsonschema2pojo")
public class Fitbit {
@SerializedName("user")
@Expose
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
User Class
imports
@Generated("jsonschema2pojo")
public class User {
@SerializedName("age")
@Expose
private Integer age;
@SerializedName("avatar")
@Expose
private String avatar;
@SerializedName("averageDailySteps")
@Expose
private Integer averageDailySteps;
@SerializedName("dateOfBirth")
@Expose
private String dateOfBirth;
@SerializedName("fullName")
@Expose
private String fullName;
@SerializedName("gender")
@Expose
private String gender;
@SerializedName("height")
@Expose
private Double height;
@SerializedName("memberSince")
@Expose
private String memberSince;
@SerializedName("startDayOfWeek")
@Expose
private String startDayOfWeek;
@SerializedName("strideLengthRunning")
@Expose
private Double strideLengthRunning;
@SerializedName("strideLengthWalking")
@Expose
private Double strideLengthWalking;
@SerializedName("timezone")
@Expose
private String timezone;
@SerializedName("waterUnitName")
@Expose
private String waterUnitName;
@SerializedName("weight")
@Expose
private Double weight;
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public Integer getAverageDailySteps() {
return averageDailySteps;
}
public void setAverageDailySteps(Integer averageDailySteps) {
this.averageDailySteps = averageDailySteps;
}
public String getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(String dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Double getHeight() {
return height;
}
public void setHeight(Double height) {
this.height = height;
}
public String getMemberSince() {
return memberSince;
}
public void setMemberSince(String memberSince) {
this.memberSince = memberSince;
}
public String getStartDayOfWeek() {
return startDayOfWeek;
}
public void setStartDayOfWeek(String startDayOfWeek) {
this.startDayOfWeek = startDayOfWeek;
}
public Double getStrideLengthRunning() {
return strideLengthRunning;
}
public void setStrideLengthRunning(Double strideLengthRunning) {
this.strideLengthRunning = strideLengthRunning;
}
public Double getStrideLengthWalking() {
return strideLengthWalking;
}
public void setStrideLengthWalking(Double strideLengthWalking) {
this.strideLengthWalking = strideLengthWalking;
}
public String getTimezone() {
return timezone;
}
public void setTimezone(String timezone) {
this.timezone = timezone;
}
public String getWaterUnitName() {
return waterUnitName;
}
public void setWaterUnitName(String waterUnitName) {
this.waterUnitName = waterUnitName;
}
public Double getWeight() {
return weight;
}
public void setWeight(Double weight) {
this.weight = weight;
}
}
JsonPlaceholderAPI Interface Class
imports
public interface JsonPlaceholderAPI {
@Headers({"Authorization: Bearer bearercodeinserted"})
@GET("https://api.fitbit.com/1/user/-/profile.json")
Call<User> getUser();
}
MainActivity
public class MainActivity extends AppCompatActivity {
private TextView textViewResult;
private JsonPlaceholderAPI jsonPlaceholderAPI;
@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textViewResult = findViewById(R.id.text_view_result);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://jsonplaceholder.typicode.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
jsonPlaceholderAPI = retrofit.create(JsonPlaceholderAPI.class);
getUser();
}
private void getUser() {
Call<User> call = jsonPlaceholderAPI.getUser();
call.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (!response.isSuccessful()) {
textViewResult.setText("Code: " + response.code());
return;
}
textViewResult.setText("Body: " + response.body());
}
@Override
public void onFailure(Call<User> call, Throwable t) {
textViewResult.setText(t.getMessage());
}
});
}
}
ANSWER
Answered 2022-Mar-27 at 00:02Solution:
Change Call<User>()
to Call<Fitbit>()
and response.body().getUser().toString()
If you want textViewResult.setText("Body: " + response.body());
to give you string representation of your User data you have to override toString()
function on your User object. For example:
public class User {
@SerializedName("age")
@Expose
...
@Override
String toString() {
return "age: " + age + " avatar: " + avatar + ....;
}
}
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit