orderByChild() on an array - android

I'm using Firebase for Android and found that the orderByChild("key") method does not seem to work on an array; I'm trying to retrieve all award_yearentries, ordered by their year value.
This is what I've came up with:
mDatabase.child("awards").orderByChild("createdAt").addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
final AwardType awardType = new AwardType();
final ArrayList<Award> awards = dataSnapshot.getValue(awardType);
}
});
Your help is greatly appreciated.
I've added the rules:
My structure like this:
{ "awards": [
{
"award_body": "2009 QR Master Design Awards",
"award_received": "Finalist for Bathrooms $30,000, Qualified Remodeler Magazine",
"createdAt": "2015-11-20T03:43:58.009Z",
"logo": {
"__type": "File",
"name": "tfss-b2a0130d-d9ac-46e6-a29f-c9d9db666909-qualirem1.png",
"url": "awards/thumbnails/tfss-b2a0130d-d9ac-46e6-a29f-c9d9db666909-qualirem1.png"
},
"objectId": "0cE0zA7ciS",
"updatedAt": "2015-11-20T03:46:57.472Z",
"year": {
"__type": "Pointer",
"className": "award_years",
"objectId": "Zp3oDtzpTY"
}
},
{
"award_body": "2014 NAHB",
"award_received": "Best of American Living Awards (BALA) Platinum Award Winner, Kitchen Remodel $100,001 \u0026 over",
"createdAt": "2015-11-20T05:36:55.359Z",
"logo": {
"__type": "File",
"name": "tfss-3cce2507-18fe-4aac-b039-54c343f27473-nahb.png",
"url": "awards/thumbnails/tfss-3cce2507-18fe-4aac-b039-54c343f27473-nahb.png"
},
"objectId": "1ckh7kjxfN",
"updatedAt": "2015-11-20T05:45:02.307Z",
"year": {
"__type": "Pointer",
"className": "award_years",
"objectId": "aL7crUC7Qc"
}
}]
}

Related

Handle custom response in Paging library 3 Android

I am new to the Paging 3 library in android kotlin. I want unlimited data. So I found the Paging 3 library helpful in my case. I used PagingSource to create a list. I am not using Room. I have multiple view in recyclerView. I am using PagingDataAdapter with diff util for my Recyclerview. I used the recommended tutorial for the Paging library from codelab and I succeeded without any problem.
Now I'm facing some problems in how to handle other data than matches
{
"status": {
"code": 200,
"message": "Matches found"
},
"data": {
"filters": {
"sortable_actions": [
{
"name": "asd",
"value": "sd",
"is_selected_filter": false
},
{
"name": "asd",
"value": "asd",
"is_selected_filter": false
}
],
"filter_actions": [
{
"name": "sdaf",
"display_name": "dafs",
"is_selected_filter": false
}
]
},
"cities": [
"Akora, Japan",
"Zurich, Switzerland"
],
"matches_count": {
"hot": 0,
"warm": 0,
"cool": 17
},
"matches": [
{
"id": "52832",
"type": "asdf",
"attributes": {
"name": "afd",
"pitch": "dsf",
"logo": "adsf",
"plan": "fd",
"country": "sdf",
"city": "faas",
}
},
{
"id": "52832",
"type": "asdf",
"attributes": {
"name": "",
"pitch": "",
"logo": "",
"plan": "",
"country": "",
"city": "",
}
},
{
"id": "52832",
"type": "",
"attributes": {
"name": "",
"pitch": "",
"logo": "",
"plan": "",
"country": "",
"city": "",
}
},
{
"id": "52832",
"type": "",
"attributes": {
"name": "",
"pitch": "",
"logo": "",
"plan": "",
"country": "",
"city": "",
}
}
]
}
}
can you please help me how to get filter and sorting data in my UI.

JSON API relationships with moshi

I'm having this response JSON that theorically follows the JSON API specs. I'm trying to parse with the moshi-jsonapi library but I don't know how to parse the some_objects relationship. In the SomeType class I have a member HasMany<SomeObject> someObjects and the class SomeObject is annotated in a proper way:
#JsonApi(type = "some_objects")
public class SomeObject extends Resource {
//....
}
But, after doing the parsing, I'm getting the someObjects member as null. Anyone knows why?
The JSON is that one:
"links": {
"self": "someurl/params"
},
"data": [
{
"type": "some_type",
"id": "12345",
"attributes": {
"attr1": 1,
"attr2": 2,
"attr3": 3
},
"relationships": {
"some_objects": {
"data": [
{
"type": "some_objects",
"id": "1"
},
{
"type": "some_objects",
"id": "2"
}
]
}
}
}
],
"included": [
{
"type": "some_objects",
"id": "1",
"attributes": {
"id": "1",
"parentId": "1"
},
"relationships": {
"subobjects": {
"data": [
{
"type": "subobjects",
"id": "2"
}
]
}
}
{
"type": "subobjects",
"id": "2",
"attributes": {
"metadata": {
"code": "AA"
},
"id": "2",
"parentId": "1"
}
}
],
"meta": {
"total": 1,
"totalCount": 1,
"correction": []
}
}
The only problem was the name of the member, after changing someObjects by 'some_objects' it worked like a charm.

How to obtain/parse JSONObject data with GSON

I am trying to use retrofit with android, which is kind of forcing me to use gson.
I am trying to get the data from the payload["response"]["docs"][0]["web_url"] in my code.
Issue : the key getResponse(), from below model class, always gives me {}. Whats the right way to handle this in android? Also note, the getCopyright() & getStatus() are working fine.
I am also providing the sample payload.
I have the model class like this :
public class ArticleSearchResponseModel {
#SerializedName("status") private String status;
#SerializedName("copyright") private String copyright;
#SerializedName("response") private JSONObject response;
public String getStatus() {
return status;
}
public String getCopyright() {
return copyright;
}
public JSONObject getResponse() {
return response;
}
public void setStatus(String status) {
this.status = status;
}
public void setCopyright(String copyright) {
this.copyright = copyright;
}
public void setResponse(JSONObject response) {
this.response = response;
}
}
My payload :
{
"response": {
"meta": {
"hits": 15987906,
"time": 108,
"offset": 0
},
"docs": [
{
"web_url": "http://www.nytimes.com/2016/11/13/insider/gender-issues-in-sharp-focus-at-the-times.html",
"snippet": "Susan Chira, senior correspondent for gender issues, and Susan Dominus, a Times Magazine writer, talk about men, women and coverage of their changing roles.",
"lead_paragraph": "Susan Chira, senior correspondent for gender issues, and Susan Dominus, a Times Magazine writer, talk about men, women and coverage of their changing roles.",
"abstract": null,
"print_page": null,
"blog": [],
"source": "The New York Times",
"multimedia": [
{
"width": 190,
"url": "images/2016/10/14/insider/14-Insider-SUSANIMAGE/14-Insider-SUSANIMAGE-thumbWide.jpg",
"height": 126,
"subtype": "wide",
"legacy": {
"wide": "images/2016/10/14/insider/14-Insider-SUSANIMAGE/14-Insider-SUSANIMAGE-thumbWide.jpg",
"wideheight": "126",
"widewidth": "190"
},
"type": "image"
},
{
"width": 600,
"url": "images/2016/10/14/insider/14-Insider-SUSANIMAGE/14-Insider-SUSANIMAGE-articleLarge.jpg",
"height": 400,
"subtype": "xlarge",
"legacy": {
"xlargewidth": "600",
"xlarge": "images/2016/10/14/insider/14-Insider-SUSANIMAGE/14-Insider-SUSANIMAGE-articleLarge.jpg",
"xlargeheight": "400"
},
"type": "image"
},
{
"width": 75,
"url": "images/2016/10/14/insider/14-Insider-SUSANIMAGE/14-Insider-SUSANIMAGE-thumbStandard.jpg",
"height": 75,
"subtype": "thumbnail",
"legacy": {
"thumbnailheight": "75",
"thumbnail": "images/2016/10/14/insider/14-Insider-SUSANIMAGE/14-Insider-SUSANIMAGE-thumbStandard.jpg",
"thumbnailwidth": "75"
},
"type": "image"
}
],
"headline": {
"main": "Gender Issues in Sharp Focus at The Times",
"content_kicker": "Insider Podcasts",
"kicker": "Insider Podcast"
},
"keywords": [
{
"rank": "1",
"is_major": "N",
"name": "subject",
"value": "Presidential Election of 2016"
},
{
"rank": "2",
"is_major": "N",
"name": "subject",
"value": "Women and Girls"
},
{
"rank": "3",
"is_major": "N",
"name": "subject",
"value": "Gender"
},
{
"rank": "4",
"is_major": "N",
"name": "subject",
"value": "Men and Boys"
},
{
"rank": "5",
"is_major": "N",
"name": "persons",
"value": "Trump, Donald J"
}
],
"pub_date": "2016-11-13T00:00:00Z",
"document_type": "article",
"news_desk": "Insider",
"section_name": "Times Insider",
"subsection_name": null,
"byline": {
"person": [
{
"organization": "",
"role": "reported",
"firstname": "Susan",
"rank": 1,
"lastname": "LEHMAN"
}
],
"original": "By SUSAN LEHMAN"
},
"type_of_material": "News",
"_id": "58011d9b253f0a0e44966174",
"word_count": null,
"slideshow_credits": null
},
{
"web_url": "http://www.nytimes.com/2016/10/25/realestate/doors-of-manhattan.html",
"snippet": "Even though they stand between us and the chaos of the city, the borough’s distinctive doors are easy to overlook.",
"lead_paragraph": "Even though they stand between us and the chaos of the city, the borough’s distinctive doors are easy to overlook.",
"abstract": null,
"print_page": null,
"blog": [],
"source": "The New York Times",
"multimedia": [],
"headline": {
"main": "Doors of Manhattan",
"content_kicker": "Voyeur",
"kicker": "Voyeur"
},
"keywords": [
{
"rank": "1",
"is_major": "N",
"name": "subject",
"value": "Real Estate and Housing (Residential)"
},
{
"rank": "2",
"is_major": "N",
"name": "subject",
"value": "Architecture"
},
{
"rank": "3",
"is_major": "N",
"name": "glocations",
"value": "Upper West Side (Manhattan, NY)"
},
{
"rank": "4",
"is_major": "N",
"name": "glocations",
"value": "Upper East Side (Manhattan, NY)"
}
],
"pub_date": "2016-10-25T00:00:00Z",
"document_type": "article",
"news_desk": "RealEstate",
"section_name": "Real Estate",
"subsection_name": null,
"byline": {
"person": [
{
"firstname": "Photographs",
"middlename": "George",
"lastname": "ETHEREDGE",
"rank": 1,
"role": "reported",
"organization": ""
}
],
"original": "Photographs by GEORGE ETHEREDGE for THE NEW YORK TIMES"
},
"type_of_material": "News",
"_id": "57e94175253f0a6bb40cbffc",
"word_count": null,
"slideshow_credits": null
},
{
"web_url": "http://cooking.nytimes.com/recipes/1018356-celery-toasts",
"snippet": "This was the first recipe that the chef and writer Gabrielle Hamilton brought to The Times as an Eat columnist for the Sunday magazine in 2016, a snack-tray-sandwich version of a celery-and-fennel salad served at her restaurant, Prune, in the East...",
"lead_paragraph": "This was the first recipe that the chef and writer Gabrielle Hamilton brought to The Times as an Eat columnist for the Sunday magazine in 2016, a snack-tray-sandwich version of a celery-and-fennel salad served at her restaurant, Prune, in the East Village. It calls for thick, white toasted Pullman bread spread wall to wall with unsalted butter, with slices of blue cheese neatly laid on top, below a mound of shaved celery and thinly sliced scallions dressed in garlic, olive oil, lemon juice and salt, and the whole shebang dusted in ground black pepper before being cut in halves or quarters. \"The ingredients come from the grocery store,\" she wrote in her column. \"These toasts are not expensive or intimidating, but they are outstanding.\"",
"abstract": null,
"print_page": null,
"blog": [],
"source": "du_recipe",
"multimedia": [
{
"credit": "Davide Luciano for The New York Times. Food stylist: Michelle Gatton. Prop stylist: Alex Brannian.",
"url": "images/2016/10/23/magazine/23eat/23eat-thumbStandard-v2.jpg",
"rank": "1",
"height": 75,
"subtype": "thumbnail",
"legacy": [],
"caption": "Celery Toasts",
"type": "image",
"width": 75
},
{
"credit": "Davide Luciano for The New York Times. Food stylist: Michelle Gatton. Prop stylist: Alex Brannian.",
"url": "images/2016/10/23/magazine/23eat/23mag-23eat-t_CA1-articleLarge.jpg",
"rank": "1",
"height": 400,
"subtype": "large",
"legacy": [],
"caption": "Celery Toasts",
"type": "image",
"width": 600
}
],
"headline": {
"main": "A Snack Tray to Gather the Family Around",
"name": "Celery Toasts"
},
"keywords": [],
"pub_date": "2016-10-23T00:00:00Z",
"document_type": "recipe",
"news_desk": null,
"section_name": null,
"subsection_name": null,
"byline": {
"person": [
{
"organization": "",
"role": "reported",
"firstname": "Gabrielle",
"rank": 1,
"lastname": "Hamilton"
}
],
"original": "Gabrielle Hamilton"
},
"type_of_material": "Recipe",
"_id": "580696f1253f0a7d028b0864",
"word_count": "101",
"slideshow_credits": null
},
{
"web_url": "http://www.nytimes.com/2016/10/23/books/review/the-story-behind-this-weeks-best-sellers.html",
"snippet": "Ruth Bader Ginsburg, whose anthology “My Own Words” is No. 12 in hardcover nonfiction, has something in common with Notorious B.I.G.",
"lead_paragraph": "Ruth Bader Ginsburg, whose anthology “My Own Words” is No. 12 in hardcover nonfiction, has something in common with Notorious B.I.G.",
"abstract": null,
"print_page": "30",
"blog": [],
"source": "The New York Times",
"multimedia": [
{
"width": 190,
"url": "images/2016/10/23/books/review/23inside-list/23inside-list-thumbWide.jpg",
"height": 126,
"subtype": "wide",
"legacy": {
"wide": "images/2016/10/23/books/review/23inside-list/23inside-list-thumbWide.jpg",
"wideheight": "126",
"widewidth": "190"
},
"type": "image"
},
{
"width": 75,
"url": "images/2016/10/23/books/review/23inside-list/23inside-list-thumbStandard.jpg",
"height": 75,
"subtype": "thumbnail",
"legacy": {
"thumbnailheight": "75",
"thumbnail": "images/2016/10/23/books/review/23inside-list/23inside-list-thumbStandard.jpg",
"thumbnailwidth": "75"
},
"type": "image"
}
],
"headline": {
"main": "The Story Behind This Week’s Best Sellers"
},
"keywords": [
{
"rank": "1",
"is_major": "N",
"name": "subject",
"value": "Books and Literature"
},
{
"rank": "2",
"is_major": "N",
"name": "persons",
"value": "Ginsburg, Ruth Bader"
}
],
"pub_date": "2016-10-23T00:00:00Z",
"document_type": "article",
"news_desk": "BookReview",
"section_name": "Books",
"subsection_name": "Book Review",
"byline": {
"person": [
{
"organization": "",
"role": "reported",
"firstname": "Gregory",
"rank": 1,
"lastname": "COWLES"
}
],
"original": "By GREGORY COWLES"
},
"type_of_material": "News",
"_id": "5800f337253f0a7985625011",
"word_count": null,
"slideshow_credits": null
},
{
"web_url": "http://www.nytimes.com/2016/10/23/books/review/ngugi-wa-thiongo-birth-of-a-dream-weaver.html",
"snippet": "A Kenyan considers his early years as a student and writer.",
"lead_paragraph": "A Kenyan considers his early years as a student and writer.",
"abstract": null,
"print_page": "25",
"blog": [],
"source": "The New York Times",
"multimedia": [
{
"width": 190,
"url": "images/2016/10/23/books/review/23Wrong/23Wrong-thumbWide.jpg",
"height": 126,
"subtype": "wide",
"legacy": {
"wide": "images/2016/10/23/books/review/23Wrong/23Wrong-thumbWide.jpg",
"wideheight": "126",
"widewidth": "190"
},
"type": "image"
},
{
"width": 600,
"url": "images/2016/10/23/books/review/23Wrong/23Wrong-articleLarge.jpg",
"height": 400,
"subtype": "xlarge",
"legacy": {
"xlargewidth": "600",
"xlarge": "images/2016/10/23/books/review/23Wrong/23Wrong-articleLarge.jpg",
"xlargeheight": "400"
},
"type": "image"
},
{
"width": 75,
"url": "images/2016/10/23/books/review/23Wrong/23Wrong-thumbStandard.jpg",
"height": 75,
"subtype": "thumbnail",
"legacy": {
"thumbnailheight": "75",
"thumbnail": "images/2016/10/23/books/review/23Wrong/23Wrong-thumbStandard.jpg",
"thumbnailwidth": "75"
},
"type": "image"
}
],
"headline": {
"main": "Ngugi wa Thiong’o on Starting Out as a Writer",
"content_kicker": "Nonfiction",
"kicker": "Nonfiction",
"print_headline": "A Long Look Back"
},
"keywords": [
{
"rank": "2",
"is_major": "N",
"name": "persons",
"value": "Thiong'o, Ngugi wa"
},
{
"rank": "3",
"is_major": "N",
"name": "subject",
"value": "Books and Literature"
},
{
"rank": "4",
"is_major": "N",
"name": "subject",
"value": "Writing and Writers"
}
],
"pub_date": "2016-10-23T00:00:00Z",
"document_type": "article",
"news_desk": "BookReview",
"section_name": "Books",
"subsection_name": "Book Review",
"byline": {
"person": [
{
"organization": "",
"role": "reported",
"firstname": "Michela",
"rank": 1,
"lastname": "WRONG"
}
],
"original": "By MICHELA WRONG"
},
"type_of_material": "Review",
"_id": "57ff4d1d253f0a6b9720abd2",
"word_count": null,
"slideshow_credits": null
},
{
"web_url": "http://cooking.nytimes.com/recipes/1018347-lemon-drizzle-cake",
"snippet": "This light and moist lemon poundcake has a crunchy sugar glaze that crystallizes on top, giving a contrasting texture to the soft crumb underneath. It’s an easy-to-make, crowd-pleasing cake that’s excellent on its own but takes well to...",
"lead_paragraph": "This light and moist lemon poundcake has a crunchy sugar glaze that crystallizes on top, giving a contrasting texture to the soft crumb underneath. It’s an easy-to-make, crowd-pleasing cake that’s excellent on its own but takes well to embellishments. A scoop of ice cream or sorbet, fruit compote and-or lemon curd are all wonderful alongside.",
"abstract": null,
"print_page": null,
"blog": [],
"source": "du_recipe",
"multimedia": [
{
"credit": "Andrew Scrivani for The New York Times",
"url": "images/2016/10/19/dining/19BAKEOFF2/19BAKEOFF2-thumbStandard.jpg",
"rank": "1",
"height": 75,
"subtype": "thumbnail",
"legacy": [],
"type": "image",
"width": 75
},
{
"credit": "Andrew Scrivani for The New York Times",
"url": "images/2016/10/19/dining/19BAKEOFF2/19BAKEOFF2-articleLarge.jpg",
"rank": "1",
"height": 400,
"subtype": "large",
"legacy": [],
"type": "image",
"width": 600
}
],
"headline": {
"main": "‘The Great British Bake Off’ Changes the Way the British Bake",
"name": "Lemon Drizzle Cake"
},
"keywords": [],
"pub_date": "2016-10-19T00:00:00Z",
"document_type": "recipe",
"news_desk": null,
"section_name": null,
"subsection_name": null,
"byline": {
"person": [
{
"organization": "",
"role": "reported",
"firstname": "Melissa",
"rank": 1,
"lastname": "Clark"
}
],
"original": "Melissa Clark"
},
"type_of_material": "Recipe",
"_id": "58066d7c253f0a7d028b07d0",
"word_count": "250",
"slideshow_credits": null
}
]
},
"status": "OK",
"copyright": "Copyright (c) 2013 The New York Times Company. All Rights Reserved."
}
Before start, I'm not familiar with retrofit.
If you want serialize/unserialize json to pojo, you better make pojo object.
class Response {
Meta meta;
List<Docs> docs;
}
class Docs {
String webUrl;
Mutimedia multimedia;
...
}
The issue the key getResponse(), from below model class, always gives me {} happens because gson cannot determine proper object to convert json to plain old java object.
In order to make your Response model class use http://www.jsonschema2pojo.org/.
Making POJO simple
you no need to make exact structure in model
you can go ahead with your code just need small change
Use
#SerializedName("response") private JsonObject response;
instead of
#SerializedName("response") private JSONObject response;
and in the import
import com.google.gson.JsonObject;

Cannot parse json with two different data types in retrofit 2.0

I'm trying to parse this json bellow, into a object named AlbumResponse that have another two objects inside, Album and PaginationInfo. Retrofit version 2.0
[
{
"id": "6",
"name": "King Stays King",
"artist_name":"Timbaland",
"image":""
},
{
"id": "7",
"name": "East Atlanta Santa 2",
"artist_name":"Gucci Mane",
"image":""
},
{
"id": "8",
"name": "The cuban connect",
"artist_name":"Phophit",
"image":""
},
{
"id": "9",
"name": "Shmoney Keeps",
"artist_name":"Calling",
"image":""
},
{
"id": "10",
"name": "Cabin Fever 3",
"artist_name":"Wiz khalifa",
"image":""
}
],
{
"nextPage": "http://private-ede172-mymixtapez1.apiary-mock.com/features/page_3/",
"itemsTotal": 10,
"page": 2,
"pagerMax": 2
}
Album class
public class Album {
long id;
String name;
#SerializedName("artist_name")
String artistName;
String image;
}
PaginationInfo class
public class PaginationInfo {
int page;
int pagerMax;
int nextPage;
int itemsTotal;
}
AlbumResponse, that have both classes above inside, and Album is a List
public class AlbumResponse {
public List<Album> albums;
public PaginationInfo paginationInfo;
}
The request
Call<AlbumResponse> responseCall = albumService.features();
responseCall.enqueue(new Callback<AlbumResponse>() {
#Override
public void onResponse(Response<AlbumResponse> response, Retrofit retrofit) {
if(response.isSuccess()) {
AlbumResponse albumResponse = response.body();
PaginationInfo paginationInfo = albumResponse.getPaginationInfo();
}
System.out.println();
}
#Override
public void onFailure(Throwable t) {
System.out.println(t.getMessage());
}
});
Interface
public interface AlbumService {
#GET("/features/")
Call<AlbumResponse> features();
}
The problem is that im getting a Throwable that contains:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $`
Please, can someone help me, i not found any answers in stackoverflow. Thanks.
The error says: the Parser expected a JSON-Object but it reads a JSON-array. To fix it (if you control the server) you should change the JSON String to something like this:
{
"albums" : [
{
"id": "6",
"name": "King Stays King",
"artist_name":"Timbaland",
"image":""
},
{
"id": "7",
"name": "East Atlanta Santa 2",
"artist_name":"Gucci Mane",
"image":""
},
{
"id": "8",
"name": "The cuban connect",
"artist_name":"Phophit",
"image":""
},
{
"id": "9",
"name": "Shmoney Keeps",
"artist_name":"Calling",
"image":""
},
{
"id": "10",
"name": "Cabin Fever 3",
"artist_name":"Wiz khalifa",
"image":""
}
],
"paginationInfo" : {
"nextPage": "http://private-ede172-mymixtapez1.apiary-mock.com/features/page_3/",
"itemsTotal": 10,
"page": 2,
"pagerMax": 2
}
}
Now it's a JSON-Object and is conform to your Java class.
If you cannot change the JSON on the backend, I would take it as row response and parse the albums Array and the PaginationInfo separately using GSON or manually.
Btw. you must change the nextPage type from int to String in the PaginationInfo class
Your JSON have a trouble in initial declaration.
According json.org:
JSON is built on two structures:
• A collection of name/value pairs. In various languages, this is
realized as an object, record, struct, dictionary, hash table, keyed
list, or associative array.
• An ordered list of values. In most
languages, this is realized as an array, vector, list, or sequence.
Try update your JSON to:
"albums": [
{
"id": "6",
"name": "King Stays King",
"artist_name":"Timbaland",
"image":""
},
{
"id": "7",
"name": "East Atlanta Santa 2",
"artist_name":"Gucci Mane",
"image":""
},
{
"id": "8",
"name": "The cuban connect",
"artist_name":"Phophit",
"image":""
},
{
"id": "9",
"name": "Shmoney Keeps",
"artist_name":"Calling",
"image":""
},
{
"id": "10",
"name": "Cabin Fever 3",
"artist_name":"Wiz khalifa",
"image":""
}
],
"pagination_info":
{
"nextPage": "http://private-ede172-mymixtapez1.apiary-mock.com/features/page_3/",
"itemsTotal": 10,
"page": 2,
"pagerMax": 2
}

Contentful Product Catalogue Error

I have download this CONTENTFUL CMS product catalogue demo ->https://github.com/contentful/product-catalogue-android. Im using android studio 1.4.
I have set the public token ID in the const.java accordingly but it still get error. At first i think maybe i have set a wrong setting at content_type field setting. But i still cannot find my solution. My error look like below and ive attached images for you to see,
10-23 18:56:18.820 2094-2147/catalogue.contentful E/SQLiteLog: (1) no such table: entry_nulundg0rwhzuvm0suntyxvdzufjrq
(1) no such table: entry_ne90ogm2rdjxuxfnb2fvs2dzbtgysw
This is my JSON statement from my CONTENTFUL "Product": content_type
{
"name": "Product",
"description": "",
"displayField": "productName",
"fields": [
{
"name": "productName",
"id": "productName",
"type": "Symbol",
"localized": false,
"validations": []
},
{
"name": "productDescription",
"id": "productDescription",
"type": "Symbol",
"localized": false,
"validations": []
},
{
"name": "sizetypecolor",
"id": "sizetypecolor",
"type": "Symbol"
},
{
"name": "images",
"id": "images",
"type": "Array",
"items": {
"type": "Link",
"linkType": "Asset",
"validations": []
},
"validations": []
},
{
"name": "categories",
"id": "categories",
"type": "Link",
"linkType": "Entry",
"validations": [
{
"linkContentType": [
"5In484EhYQS4ICSauCeAcE"
]
}
]
},
{
"name": "tags",
"id": "tags",
"type": "Array",
"items": {
"type": "Symbol",
"validations": []
},
"validations": []
},
{
"name": "price",
"id": "price",
"type": "Number",
"validations": []
},
{
"name": "brand",
"id": "brand",
"type": "Link",
"linkType": "Entry",
"validations": [
{
"linkContentType": [
"5gTQW9EcAwEYEc42WGgaEu"
]
}
]
},
{
"name": "quantity",
"id": "quantity",
"type": "Integer",
"localized": false,
"validations": []
},
{
"name": "sku",
"id": "sku",
"type": "Symbol",
"localized": false,
"validations": []
},
{
"name": "website",
"id": "website",
"type": "Symbol",
"localized": false,
"validations": []
}
],
"sys": {
"id": "4Ot8c6D2qQqgoaUKgYm82K",
"type": "ContentType",
"createdAt": "2015-10-23T13:04:54.705Z",
"createdBy": {
"sys": {
"type": "Link",
"linkType": "User",
"id": "2P70I7YlhYLnC0iOpPYYwN"
}
},
"space": {
"sys": {
"type": "Link",
"linkType": "Space",
"id": "b7di2z8ukacn"
}
},
"firstPublishedAt": "2015-10-23T13:04:59.904Z",
"publishedCounter": 17,
"publishedAt": "2015-10-23T17:33:41.088Z",
"publishedBy": {
"sys": {
"type": "Link",
"linkType": "User",
"id": "2P70I7YlhYLnC0iOpPYYwN"
}
},
"publishedVersion": 41,
"version": 42,
"updatedAt": "2015-10-23T17:33:41.107Z",
"updatedBy": {
"sys": {
"type": "Link",
"linkType": "User",
"id": "2P70I7YlhYLnC0iOpPYYwN"
}
}
}
}
And this is my Android Studio coding
public Product$$ModelHelper() {
fields.add(FieldMeta.builder().setId("productName").setName("name").setSqliteType("STRING").build());
fields.add(FieldMeta.builder().setId("productDescription").setName("description").setSqliteType("STRING").build());
fields.add(FieldMeta.builder().setId("sizetypecolor").setName("sizeTypeColor").setSqliteType("STRING").build());
fields.add(FieldMeta.builder().setId("image").setName("images").setArrayType("com.contentful.vault.Asset").build());
fields.add(FieldMeta.builder().setId("tags").setName("tags").setSqliteType("BLOB").setArrayType("java.lang.String").build());
fields.add(FieldMeta.builder().setId("categories").setName("categories").setArrayType("catalogue.contentful.vault.Category").build());
fields.add(FieldMeta.builder().setId("price").setName("price").setSqliteType("DOUBLE").build());
fields.add(FieldMeta.builder().setId("brand").setName("brand").setLinkType("ENTRY").build());
fields.add(FieldMeta.builder().setId("quantity").setName("quantity").setSqliteType("INT").build());
fields.add(FieldMeta.builder().setId("sku").setName("sku").setSqliteType("STRING").build());
fields.add(FieldMeta.builder().setId("website").setName("website").setSqliteType("STRING").build());
}
#Override
public List<FieldMeta> getFields() {
return fields;
}
#Override
public String getTableName() {
return "entry_ne90ogm2rdjxuxfnb2fvs2dzbtgysw";
}
My Android Studio project error screenshot
I really appreciate if anyone can help me with this problem.Because this app is a demo, i really think my problem is at my setting at CONTENTFUL, but maybe i need second opinion. Please help.
Thank you.
Hello Mario from Contentful here,
As I could see from the code you provided, it seems as if you changed the generated classes. Can you try changing the Product.java using the annotations provided by vault to create a Product matching your data?
This also needs to be done with all the other ContentTypes, you created in the Contentful-WebUI.

Categories

Resources