I have a collection of document inside another document. Would like to implement pagination on nested element while fetching the data. Could you please let me know how to do that? In the structure I would like to fetch messages using pagination.
public abstract class CommonDomainAttributes implements Serializable, Cloneable {
private static final long serialVersionUID = 1L;
#Id
protected String id;
#JsonIgnore
#CreatedDate
protected Date createDate;
//#JsonIgnore
#LastModifiedDate
//#JsonSerialize(using=JsonDateSerializer.class)
protected Date lastModifiedDate;
#JsonIgnore
#CreatedBy
protected String createdBy;
#JsonIgnore
#LastModifiedBy
protected String lastModifiedBy;
/**
* #return the id
*/
public String getId() {
return id;
}
/**
* #param id the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* #return the createDate
*/
public Date getCreateDate() {
return createDate;
}
/**
* #param createDate the createDate to set
*/
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
/**
* #return the lastModifiedDate
*/
public Date getLastModifiedDate() {
return lastModifiedDate;
}
/**
* #param lastModifiedDate the lastModifiedDate to set
*/
public void setLastModifiedDate(Date lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
/**
* #return the createdBy
*/
public String getCreatedBy() {
return createdBy;
}
/**
* #param createdBy the createdBy to set
*/
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
/**
* #return the lastModifiedBy
*/
public String getLastModifiedBy() {
return lastModifiedBy;
}
/**
* #param lastModifiedBy the lastModifiedBy to set
*/
public void setLastModifiedBy(String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
/* (non-Javadoc)
* #see java.lang.Object#hashCode()
*/
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (id == null ? 0 : id.hashCode());
return result;
}
/* (non-Javadoc)
* #see java.lang.Object#equals(java.lang.Object)
*/
#Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
CommonDomainAttributes other = (CommonDomainAttributes) obj;
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
return true;
}
/* (non-Javadoc)
* #see java.lang.Object#toString()
*/
#Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("CommonDomainAttributes [id=").append(id)
.append(", createDate=").append(createDate)
.append(", lastModifiedDate=").append(lastModifiedDate)
.append(", createdBy=").append(createdBy)
.append(", lastModifiedBy=").append(lastModifiedBy)
.append(", toString()=").append(super.toString()).append("]");
return builder.toString();
}
}
public class Message extends CommonDomainAttributes implements Serializable{
private String fromuserId;
private String fromuserName;
private String toUserId;
private String touserName;
private String message;
/**
* #return the fromuserId
*/
public String getFromuserId() {
return fromuserId;
}
/**
* #param fromuserId the fromuserId to set
*/
public void setFromuserId(String fromuserId) {
this.fromuserId = fromuserId;
}
/**
* #return the fromuserName
*/
public String getFromuserName() {
return fromuserName;
}
/**
* #param fromuserName the fromuserName to set
*/
public void setFromuserName(String fromuserName) {
this.fromuserName = fromuserName;
}
/**
* #return the toUserId
*/
public String getToUserId() {
return toUserId;
}
/**
* #param toUserId the toUserId to set
*/
public void setToUserId(String toUserId) {
this.toUserId = toUserId;
}
/**
* #return the touserName
*/
public String getTouserName() {
return touserName;
}
/**
* #param touserName the touserName to set
*/
public void setTouserName(String touserName) {
this.touserName = touserName;
}
/**
* #return the message
*/
public String getMessage() {
return message;
}
/**
* #param message the message to set
*/
public void setMessage(String message) {
this.message = message;
}
/* (non-Javadoc)
* #see java.lang.Object#toString()
*/
#Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Message [fromuserId=");
builder.append(fromuserId);
builder.append(", fromuserName=");
builder.append(fromuserName);
builder.append(", toUserId=");
builder.append(toUserId);
builder.append(", touserName=");
builder.append(touserName);
builder.append(", message=");
builder.append(message);
builder.append(", toString()=");
builder.append(super.toString());
builder.append("]");
return builder.toString();
}
}
#Document(collection="discussion")
#TypeAlias("discussion")
public class Discussion extends CommonDomainAttributes implements Serializable{
private String discussionTopic;
private List<Message> messages;
/**
* #return the discussionTopic
*/
public String getDiscussionTopic() {
return discussionTopic;
}
/**
* #param discussionTopic the discussionTopic to set
*/
public void setDiscussionTopic(String discussionTopic) {
this.discussionTopic = discussionTopic;
}
/**
* #return the messages
*/
public List<Message> getMessages() {
return messages;
}
/**
* #param messages the messages to set
*/
public void setMessages(List<Message> messages) {
this.messages = messages;
}
/**
* #param messages the messages to set
*/
public void addMessages(Message message) {
if(null == messages){
messages = new LinkedList<>();
}
messages.add(message);
}
/* (non-Javadoc)
* #see java.lang.Object#toString()
*/
#Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Discussion [discussionTopic=");
builder.append(discussionTopic);
builder.append(", messages=");
builder.append(messages);
builder.append(", toString()=");
builder.append(super.toString());
builder.append("]");
return builder.toString();
}
}
A bit on Mongo Query Language
In MongoDB, the $slice operator controls the number of items of an array that a query returns. The $slice operator can accept values with following syntax:
[toSkip, toLimit]
Where the first value indicates the number of items in the array to skip and the second value indicates the number of items to return. For example, you can use the following query:
db.discussions.find({}, {messages: {$slice: [20, 10]}})
To return 10 messages, after skipping the first 20 messages of that array.
Bring it to Spring Data World
In order to use $slice operator with Spring Data MongoDB, you should use #Query annotation and its fields attribute. For example, if you have a DiscussionRepository, you could write something like:
public interface DiscussionRepository extends MongoRepository<Discussion, String> {
#Query(value = "{}", fields = "{messages: {$slice: [?0, ?1]}}")
List<Discussion> findDiscussions(int skip, int limit);
}
With this arrangement, following method call:
discussionRepository.findDiscussions(20, 10)
Would generate the same result as:
db.discussions.find({}, {messages: {$slice: [20, 10]}})
With a little bit of work, you can turn the Skip/Limit combination to a pagination functionality.
Related
Hello i was trying to deserialize the following JSON response from a Web Api:
{
"response": [
370968,
{
"aid": 65843156,
"owner_id": 17519165,
"artist": "Bass Test",
"title": "дурной басс!",
"duration": 238,
"url": "http://cs6-10v4.vk-cdn.net/p22/c412a04df93035.mp3?extra=9YguhLftfZDDwo4JKBVwvlx_V1vwlu5pNU4-WremEqM9bL8eN2vh3_qu7bAg9EgNCj0ztEcMurarC499x8X2MpUaipykG2LDueWe0QQMrIPplkxKdV1xcQp35baDwA84l-luVxai9maX",
"lyrics_id": "6214304"
},
{
"aid": 207425918,
"owner_id": 96085484,
"artist": "► DJ Pleased",
"title": "Bass Test № 04 (New 2013)",
"duration": 328,
"url": "http://cs6-7v4.vk-cdn.net/p23/6d7071221fb912.mp3?extra=O5ih5W5YkaEkXhHQSOKeDzvtr0V8xyS1WhIgjYLROFOMcW__FpU3mSf5udwdEAq6kkcz7QSy5jB57rTgSxnRJXCySZy2b0J_a2DvzFUBqVX6lcKqlarTryP_loQyk-SYPbFLh-9mSzm_iA",
"lyrics_id": "86651563",
"genre": 10
}
]
}
My intention is to build a class to get the items in the response and use them in my Java Android application. The problem is that the first item of the response array is a number and not an object like the next items. So when I parse it with Gson it gives me the error:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was NUMBER at line 1 column 20 path $.response[0]
I used the retrofit android library with the following POJO class (witch works if i don't have the counter in the response):
import java.util.HashMap;
import java.util.Map;
public class Response {
private Integer aid;
private Integer ownerId;
private String artist;
private String title;
private Integer duration;
private String url;
private String lyricsId;
private Integer genre;
private String album;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
/**
*
* #return
* The aid
*/
public Integer getAid() {
return aid;
}
/**
*
* #param aid
* The aid
*/
public void setAid(Integer aid) {
this.aid = aid;
}
/**
*
* #return
* The ownerId
*/
public Integer getOwnerId() {
return ownerId;
}
/**
*
* #param ownerId
* The owner_id
*/
public void setOwnerId(Integer ownerId) {
this.ownerId = ownerId;
}
/**
*
* #return
* The artist
*/
public String getArtist() {
return artist;
}
/**
*
* #param artist
* The artist
*/
public void setArtist(String artist) {
this.artist = artist;
}
/**
*
* #return
* The title
*/
public String getTitle() {
return title;
}
/**
*
* #param title
* The title
*/
public void setTitle(String title) {
this.title = title;
}
/**
*
* #return
* The duration
*/
public Integer getDuration() {
return duration;
}
/**
*
* #param duration
* The duration
*/
public void setDuration(Integer duration) {
this.duration = duration;
}
/**
*
* #return
* The url
*/
public String getUrl() {
return url;
}
/**
*
* #param url
* The url
*/
public void setUrl(String url) {
this.url = url;
}
/**
*
* #return
* The lyricsId
*/
public String getLyricsId() {
return lyricsId;
}
/**
*
* #param lyricsId
* The lyrics_id
*/
public void setLyricsId(String lyricsId) {
this.lyricsId = lyricsId;
}
/**
*
* #return
* The genre
*/
public Integer getGenre() {
return genre;
}
/**
*
* #param genre
* The genre
*/
public void setGenre(Integer genre) {
this.genre = genre;
}
/**
*
* #return
* The album
*/
public String getAlbum() {
return album;
}
/**
*
* #param album
* The album
*/
public void setAlbum(String album) {
this.album = album;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
Is there any way to make it work? I don't have access to the API server so i cant change how the result is displayed. To generate the class i used http://www.jsonschema2pojo.org/ but i was able to generate it only by removing the counter from the response.
The wrapper class VKSongApi:
public class VKSongApi {
private List<Response> response = new ArrayList<Response>();
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
/**
*
* #return
* The response
*/
public List<Response> getResponse() {
return response;
}
/**
*
* #param response
* The response
*/
public void setResponse(List<Response> response) {
this.response = response;
}
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
The retrofit interface class is:
public interface VKApi {
#GET("/method/audio.search")
Call<VKSongApi> search(#Query("q") String query, #Query("access_token") String token);
}
Then in the MainActivity i do:
public static final String BASE_URL = "https://api.vk.com/method/";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
VKApi apiService =
retrofit.create(VKApi.class);
And call the method from the MainActivity with:
Call<VKSongApi> call = apiService.search("test","fff9ef502df4bb10d9bf50dcd62170a24c69e98e4d847d9798d63dacf474b674f9a512b2b3f7e8ebf1d69");
call.enqueue(new Callback<VKSongApi>() {
#Override
public void onResponse(Call<VKSongApi> call, Response<VKSongApi> response) {
int statusCode = response.code();
VKSongApi song = response.body();
Log.d(TAG,response.message());
}
#Override
public void onFailure(Call<VKSongApi> call, Throwable t) {
//Here the error occurs com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was NUMBER at line 1 column 20 path $.response[0]
Log.d(TAG,"Failure");
}
});
I solved by parsing manually the response using a custom deserializer class
Ok so heres the thing I am working with an api that for one JSON parameter can return two different types. So I can receive from the server either a JSON Object or a String. I'm pretty new to Android development so if someone could explain to me with maybe a code example how I can handle that problem.
Example json responses {video:"ID OF VIDEO"} or {video:{id:"ID OF VIDEO",...extra data}}. I had a look at custom deserialisers but can't find an example that is easy to follow. There must be a simple way of solving my problem. Currently I receive error "Expected string but found BEGIN OBJECT"
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class MyNotification {
#SerializedName("_id")
#Expose
private String Id;
#SerializedName("comment")
#Expose
private String comment;
#SerializedName("createdAt")
#Expose
private String createdAt;
#SerializedName("message")
#Expose
private String message;
#SerializedName("read")
#Expose
private Boolean read;
#SerializedName("recipient")
#Expose
private String recipient;
#SerializedName("sender")
#Expose
private User sender;
#SerializedName("type")
#Expose
private String type;
// #SerializedName("video")
// #Expose
// private String video;
/**
*
* #return
* The Id
*/
public String getId() {
return Id;
}
/**
*
* #param Id
* The _id
*/
public void setId(String Id) {
this.Id = Id;
}
/**
*
* #return
* The comment
*/
public String getComment() {
return comment;
}
/**
*
* #param comment
* The comment
*/
public void setComment(String comment) {
this.comment = comment;
}
/**
*
* #return
* The createdAt
*/
public String getCreatedAt() {
return createdAt;
}
/**
*
* #param createdAt
* The createdAt
*/
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
/**
*
* #return
* The message
*/
public String getMessage() {
return message;
}
/**
*
* #param message
* The message
*/
public void setMessage(String message) {
this.message = message;
}
/**
*
* #return
* The read
*/
public Boolean getRead() {
return read;
}
/**
*
* #param read
* The read
*/
public void setRead(Boolean read) {
this.read = read;
}
/**
*
* #return
* The recipient
*/
public String getRecipient() {
return recipient;
}
/**
*
* #param recipient
* The recipient
*/
public void setRecipient(String recipient) {
this.recipient = recipient;
}
/**
*
* #return
* The sender
*/
public User getSender() {
return sender;
}
/**
*
* #param sender
* The sender
*/
public void setSender(User sender) {
this.sender = sender;
}
/**
*
* #return
* The type
*/
public String getType() {
return type;
}
/**
*
* #param type
* The type
*/
public void setType(String type) {
this.type = type;
}
// /**
// *
// * #return
// * The video
// */
// public String getVideo() {
// return video;
// }
//
// /**
// *
// * #param video
// * The video
// */
// public void setVideo(String video) {
// this.video = video;
// }
}
and the part that craps out
Gson gson = new Gson();
String jsonString = String.valueOf(dataset);
Type listType = new TypeToken<List<MyNotification>>(){}.getType();
notficationsList = (List<MyNotification>) gson.fromJson(jsonString, listType);
Sorry it took so long:
Your best bet is to repair the JSON, if you must map it to an Object.
Try cleaning the JSON with this code:
public static String cleanJson(String json) {
int videoPos = json.indexOf("video");
if(videoPos == -1) {
return json; //return, no video here
}
boolean isObject = false;
int objectBegin = -1;
String cleanedJson = json.replaceAll("\\\"", "\\\\");
for(int i = videoPos; i < cleanedJson.length(); i++) {
if(cleanedJson.charAt(i) == '"') {
System.out.println("string");
return json; // its a string anyway
}
if(cleanedJson.charAt(i) == '{') {
//its an object
// i now is the position beginning the object
objectBegin = i;
}
} //replace " with space
if(objectBegin == -1) {// we did not find any { or " it is a string
return json;
}
boolean inString = false;
int objectEnd = -1;
for(int i = objectBegin; i < cleanedJson.length(); i++) {
//looking for the end of the object;
if(cleanedJson.charAt(i) == '"') inString = !inString;
if(cleanedJson.charAt(i) == '}') {
objectEnd = i;
break;
}
}
if(objectEnd != -1) {
String start = json.substring(0,objectBegin);
String videoPart = json.substring(objectBegin, objectEnd+1);
String end = json.substring(objectEnd+1);
// now we want to get the id
String newVideoPart = "";
int idStart = videoPart.indexOf("id");
int idStringStart = -1;
int idStringEnd = -1;
for(int i = idStart; i < videoPart.length(); i++) {
if(videoPart.charAt(i) == '"') {
if(idStringStart == -1) {
idStringStart = i;
} else {
idStringEnd = i;
break;
}
}
}
if(idStringStart != -1 && idStringEnd != -1) {
newVideoPart = videoPart.substring(idStringStart, idStringEnd+1);
}
return start+newVideoPart+end;
}
return json;
}
Works with these two test jsons:
System.out.println(cleanJson("{video:\"1234\"}"));
System.out.println(cleanJson("{video:{id:\"2345\", name=\"test\"}}"));
Try it like this:
notficationsList = (List<MyNotification>) gson.fromJson(cleanJson(jsonString), listType);
Ok so the solution I went with I wrote my own type adapter that gson allow you to use
public class Helper_StringAdapter extends TypeAdapter<String>{
#Override
public String read(com.google.gson.stream.JsonReader in) throws IOException {
if(in.peek() == JsonToken.NULL){
in.nextNull();
return null;
}else if(in.peek() == JsonToken.BEGIN_OBJECT && in.getPath().contains(".video")){
L.e("VIDEO IS AN OBJECT!");
String userId = readAndReturnVideoId(in);
return userId;
}else{
return in.nextString();
}
}
private String readAndReturnVideoId(com.google.gson.stream.JsonReader reader) throws IOException{
String id = "";
reader.beginObject();
while(reader.hasNext()){
String name = reader.nextName();
if(name.equals("_id")){
id = reader.nextString();
}else{
reader.skipValue();
}
}
reader.endObject();
L.e("READ ID RETURNED"+id);
return id;
}
#Override
public void write(com.google.gson.stream.JsonWriter out, String value) throws IOException {
L.e("TEST "+out);
}
}
Then in my activity data manager (Recyclerview Adapter)
public void updateData (JSONArray dataset) {
GsonBuilder gsonb = new GsonBuilder();
gsonb.registerTypeAdapter(String.class,new Helper_StringAdapter());
Gson gson = gsonb.create();
String jsonString = String.valueOf(dataset);
Type listType = new TypeToken<List<FrameNotification>>(){}.getType();
notficationsList = (List<FrameNotification>) gson.fromJson(jsonString, listType);
}
Seems to do the job
I have a servlet method that creates a JPA entity and assigns an existing JPA entity to a #ManyToOne field
When I persist it, it saves the entity but the foreign key is NULL. Why?
Here are my entities:
#Entity
public class SimpleEntity implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = -5930519292861829894L;
#Id #GeneratedValue
Long id;
String name;
#ManyToOne()
#JoinColumn(name="simple_entity_group_id", insertable=false, updatable=false, nullable=true)
SimpleEntityGroup group;
/**
*
*/
public SimpleEntity() {
}
/**
* #return the id
*/
public Long getId() {
return this.id;
}
/**
* #param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* #return the name
*/
public String getName() {
return this.name;
}
/**
* #param name the name to set
*/
/**
* #param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/* (non-Javadoc)
* #see java.lang.Object#toString()
*/
#Override
public String toString() {
return "SimpleEntity [id=" + this.id + ", name=" + this.name + ", group=" + this.getGroup() + "]";
}
/**
* #return the group
*/
public SimpleEntityGroup getGroup() {
return this.group;
}
/**
* #param group the group to set
*/
public void setGroup(SimpleEntityGroup group) {
this.group = group;
}
}
#Entity
public class SimpleEntityGroup implements Serializable {
/**
*
*/
private static final long serialVersionUID = -1680386377742600266L;
#Id #GeneratedValue
Long id;
String name;
#OneToMany(mappedBy="group")
java.util.List<SimpleEntity> simpleEntities;
/**
*
*/
public SimpleEntityGroup() {
simpleEntities = new ArrayList<SimpleEntity>();
}
/**
* #return the id
*/
public Long getId() {
return this.id;
}
/**
* #param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* #return the name
*/
public String getName() {
return this.name;
}
/**
* #param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* #return the simpleEntities
*/
public java.util.List<SimpleEntity> getSimpleEntities() {
return this.simpleEntities;
}
/**
* #param simpleEntities the simpleEntities to set
*/
public void setSimpleEntities(java.util.List<SimpleEntity> simpleEntities) {
this.simpleEntities = simpleEntities;
}
public void addSimpleEntity(SimpleEntity e) {
if(this.getSimpleEntities() != null) {
this.getSimpleEntities().add(e);
return;
}
throw new RuntimeException("Entity list is null!!!");
}
/* (non-Javadoc)
* #see java.lang.Object#toString()
*/
#Override
public String toString() {
return "SimpleEntityGroup [id=" + this.id + ", name=" + this.name + "]";
}
/* (non-Javadoc)
* #see java.lang.Object#hashCode()
*/
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
return result;
}
/* (non-Javadoc)
* #see java.lang.Object#equals(java.lang.Object)
*/
#Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
SimpleEntityGroup other = (SimpleEntityGroup) obj;
if (this.id == null) {
if (other.id != null) {
return false;
}
} else if (!this.id.equals(other.id)) {
return false;
}
return true;
}
}
Here is how I persist it:
SimpleEntity e = new SimpleEntity();
e.setName("Mike");
SimpleEntityGroup g = dao.getGroupById(1l);
e.setGroup(g);
dao.persist(e);
System.out.println(e);
System.out.println(dao.findAll());
Here is the output from the Java code, the group is set on the entry but it is not saved. Why?!?!
SimpleEntity [id=4, name=Mike, group=SimpleEntityGroup [id=1,
name=Group 1]]
[SimpleEntity [id=4, name=Mike, group=null]]
Of course I just figured it out, needed to do:
#ManyToOne()
#JoinColumn(name="simple_entity_group_id")
SimpleEntityGroup group;
-- Got rid of the insert=false, update=false
You only posted your child class but I think will be better if you also include the parent class code. I had the same problem when I tried make saves in cascade using only auto generated ids. I could solve it using the next annotations.
In my parent class I have
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name="IDCOBPRES", unique=true, nullable=false)
public Long getIdcobpres() {
return this.idcobpres;
}
//....
#OneToMany(fetch=FetchType.LAZY, mappedBy="cobpresGestion")
#Cascade({CascadeType.ALL})
public Set<CobpresOptionDet> getCobpresOptionDets() {
return this.cobpresOptionDets;
}
In my child class I have
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name="IDOPTIONDET", unique=true, nullable=false)
public Long getIdoptiondet() {
return this.idoptiondet;
}
//...
#ManyToOne(fetch=FetchType.LAZY, optional=false)
#JoinColumn(name="IDCOBPRES", nullable=false, insertable=true, updatable=true)
public CobpresGestion getCobpresGestion() {
return this.cobpresGestion;
}
So I'm trying to solve a problem that I have with my custom TypeAdapter with Gson and Retrofit. I keep getting a Expected BEGIN_OBJECT but was STRING error but I'm not really sure how to solve it. Previously I was getting a Expected BEGIN_ARRAY but was STRING error and I solved that. I'm not sure if it needs to be the same way with this new error. I've listed my classes below and any help is appreciated. This is what my json looks like here: http://pastie.org/private/bfo86iznldacbz10rtsdsg The main problem is the multimedia field in the json. It's an empty string if there is no value but if there is a value, it returns a jsonarray that contains jsonobjects.
ArrayAdapter.java
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
public class ArrayAdapter<T> extends TypeAdapter<List<T>> {
private Class<T> adapterclass;
public ArrayAdapter(Class<T> adapterclass) {
this.adapterclass = adapterclass;
}
public List<T> read(JsonReader reader) throws IOException {
List<T> list = new ArrayList<T>();
Gson gson = new GsonBuilder()
.registerTypeAdapterFactory(new ArrayAdapterFactory())
.create();
if (reader.peek() == JsonToken.STRING) {
T inning = gson.fromJson(reader, adapterclass);
list.add(inning);
} else if (reader.peek() == JsonToken.BEGIN_ARRAY) {
reader.beginArray();
while (reader.hasNext()) {
T inning = gson.fromJson(reader, adapterclass);
list.add(inning);
}
reader.endArray();
} else if (reader.peek() == JsonToken.BEGIN_OBJECT) {
reader.beginObject();
while(reader.hasNext()) {
}
}
return list;
}
public void write(JsonWriter writer, List<T> value) throws IOException {
}
}
ArraryAdapterFactory
import java.lang.reflect.ParameterizedType;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
public class ArrayAdapterFactory implements TypeAdapterFactory {
#SuppressWarnings({ "unchecked", "rawtypes" })
#Override
public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> type) {
TypeAdapter<T> typeAdapter = null;
try {
if (type.getRawType() == List.class)
typeAdapter = new ArrayAdapter(
(Class) ((ParameterizedType) type.getType())
.getActualTypeArguments()[0]);
} catch (Exception e) {
e.printStackTrace();
}
return typeAdapter;
}
}
Times.java
public class NYTimes {
// uses the new york times api
// gets the top stores on the nytimes homepage
private static final String API_URL = "http://api.nytimes.com/svc/news/v3/content/all/all";
static Gson gson = new GsonBuilder().registerTypeAdapterFactory(new ArrayAdapterFactory()).create();
private static final RestAdapter REST_ADAPTER = new RestAdapter.Builder()
.setConverter(new GsonConverter(gson))
.setEndpoint(API_URL)
.build();
private static final NYTimesService SERVICE = REST_ADAPTER.create(NYTimesService.class);
public static NYTimesService getService() {
return SERVICE;
}
}
POJO Classes
News.java
public class News {
#Expose
private String status;
#Expose
private String copyright;
#SerializedName("num_results")
#Expose
private Integer numResults;
#Expose
private List<Result> results = new ArrayList<Result>();
/**
*
* #return
* The status
*/
public String getStatus() {
return status;
}
/**
*
* #param status
* The status
*/
public void setStatus(String status) {
this.status = status;
}
/**
*
* #return
* The copyright
*/
public String getCopyright() {
return copyright;
}
/**
*
* #param copyright
* The copyright
*/
public void setCopyright(String copyright) {
this.copyright = copyright;
}
/**
*
* #return
* The numResults
*/
public Integer getNumResults() {
return numResults;
}
/**
*
* #param numResults
* The num_results
*/
public void setNumResults(Integer numResults) {
this.numResults = numResults;
}
/**
*
* #return
* The results
*/
public List<Result> getResults() {
return results;
}
/**
*
* #param results
* The results
*/
public void setResults(List<Result> results) {
this.results = results;
}
}
Result.java
public class Result {
#Expose
private String section;
#Expose
private String subsection;
#Expose
private String title;
#SerializedName("abstract")
#Expose
private String _abstract;
#Expose
private String url;
#Expose
private String byline;
#SerializedName("thumbnail_standard")
#Expose
private String thumbnailStandard;
#SerializedName("item_type")
#Expose
private String itemType;
#Expose
private String source;
#SerializedName("updated_date")
#Expose
private String updatedDate;
#SerializedName("created_date")
#Expose
private String createdDate;
#SerializedName("published_date")
#Expose
private String publishedDate;
#SerializedName("material_type_facet")
#Expose
private String materialTypeFacet;
#Expose
private String kicker;
#Expose
private String subheadline;
#SerializedName("des_facet")
#Expose
private List<String> desFacet = new ArrayList<>();
#SerializedName("org_facet")
#Expose
private List<String> orgFacet = new ArrayList<>();
#SerializedName("per_facet")
#Expose
private List<String> perFacet = new ArrayList<>();
#SerializedName("geo_facet")
#Expose
private List<String> geoFacet = new ArrayList<>();
#SerializedName("related_urls")
#Expose
private Object relatedUrls;
#Expose
private List<Multimedium> multimedia;
/**
*
* #return
* The section
*/
public String getSection() {
return section;
}
/**
*
* #param section
* The section
*/
public void setSection(String section) {
this.section = section;
}
/**
*
* #return
* The subsection
*/
public String getSubsection() {
return subsection;
}
/**
*
* #param subsection
* The subsection
*/
public void setSubsection(String subsection) {
this.subsection = subsection;
}
/**
*
* #return
* The title
*/
public String getTitle() {
return title;
}
/**
*
* #param title
* The title
*/
public void setTitle(String title) {
this.title = title;
}
/**
*
* #return
* The _abstract
*/
public String getAbstract() {
return _abstract;
}
/**
*
* #param _abstract
* The abstract
*/
public void setAbstract(String _abstract) {
this._abstract = _abstract;
}
/**
*
* #return
* The url
*/
public String getUrl() {
return url;
}
/**
*
* #param url
* The url
*/
public void setUrl(String url) {
this.url = url;
}
/**
*
* #return
* The byline
*/
public String getByline() {
return byline;
}
/**
*
* #param byline
* The byline
*/
public void setByline(String byline) {
this.byline = byline;
}
/**
*
* #return
* The thumbnailStandard
*/
public String getThumbnailStandard() {
return thumbnailStandard;
}
/**
*
* #param thumbnailStandard
* The thumbnail_standard
*/
public void setThumbnailStandard(String thumbnailStandard) {
this.thumbnailStandard = thumbnailStandard;
}
/**
*
* #return
* The itemType
*/
public String getItemType() {
return itemType;
}
/**
*
* #param itemType
* The item_type
*/
public void setItemType(String itemType) {
this.itemType = itemType;
}
/**
*
* #return
* The source
*/
public String getSource() {
return source;
}
/**
*
* #param source
* The source
*/
public void setSource(String source) {
this.source = source;
}
/**
*
* #return
* The updatedDate
*/
public String getUpdatedDate() {
return updatedDate;
}
/**
*
* #param updatedDate
* The updated_date
*/
public void setUpdatedDate(String updatedDate) {
this.updatedDate = updatedDate;
}
/**
*
* #return
* The createdDate
*/
public String getCreatedDate() {
return createdDate;
}
/**
*
* #param createdDate
* The created_date
*/
public void setCreatedDate(String createdDate) {
this.createdDate = createdDate;
}
/**
*
* #return
* The publishedDate
*/
public String getPublishedDate() {
return publishedDate;
}
/**
*
* #param publishedDate
* The published_date
*/
public void setPublishedDate(String publishedDate) {
this.publishedDate = publishedDate;
}
/**
*
* #return
* The materialTypeFacet
*/
public String getMaterialTypeFacet() {
return materialTypeFacet;
}
/**
*
* #param materialTypeFacet
* The material_type_facet
*/
public void setMaterialTypeFacet(String materialTypeFacet) {
this.materialTypeFacet = materialTypeFacet;
}
/**
*
* #return
* The kicker
*/
public String getKicker() {
return kicker;
}
/**
*
* #param kicker
* The kicker
*/
public void setKicker(String kicker) {
this.kicker = kicker;
}
/**
*
* #return
* The subheadline
*/
public String getSubheadline() {
return subheadline;
}
/**
*
* #param subheadline
* The subheadline
*/
public void setSubheadline(String subheadline) {
this.subheadline = subheadline;
}
/**
*
* #return
* The desFacet
*/
public List<String> getDesFacet() {
return desFacet;
}
/**
*
* #param desFacet
* The des_facet
*/
public void setDesFacet(List<String> desFacet) {
this.desFacet = desFacet;
}
/**
*
* #return
* The orgFacet
*/
public List<String> getOrgFacet() {
return orgFacet;
}
/**
*
* #param orgFacet
* The org_facet
*/
public void setOrgFacet(List<String> orgFacet) {
this.orgFacet = orgFacet;
}
/**
*
* #return
* The perFacet
*/
public List<String> getPerFacet() {
return perFacet;
}
/**
*
* #param perFacet
* The per_facet
*/
public void setPerFacet(List<String> perFacet) {
this.perFacet = perFacet;
}
/**
*
* #return
* The geoFacet
*/
public List<String> getGeoFacet() {
return geoFacet;
}
/**
*
* #param geoFacet
* The geo_facet
*/
public void setGeoFacet(List<String> geoFacet) {
this.geoFacet = geoFacet;
}
/**
*
* #return
* The relatedUrls
*/
public Object getRelatedUrls() {
return relatedUrls;
}
/**
*
* #param relatedUrls
* The related_urls
*/
public void setRelatedUrls(Object relatedUrls) {
this.relatedUrls = relatedUrls;
}
/**
*
* #return
* The multimedia
*/
public List<Multimedium> getMultimedia() {
return multimedia;
}
/**
*
* #param multimedia
* The multimedia
*/
public void setMultimedia(List<Multimedium> multimedia) {
this.multimedia = multimedia;
}
}
Multimedium.java
public class Multimedium {
#Expose
private String url;
#Expose
private String format;
#Expose
private Integer height;
#Expose
private Integer width;
#Expose
private String type;
#Expose
private String subtype;
#Expose
private Object caption;
#Expose
private Object copyright;
/**
*
* #return
* The url
*/
public String getUrl() {
return url;
}
/**
*
* #param url
* The url
*/
public void setUrl(String url) {
this.url = url;
}
/**
*
* #return
* The format
*/
public String getFormat() {
return format;
}
/**
*
* #param format
* The format
*/
public void setFormat(String format) {
this.format = format;
}
/**
*
* #return
* The height
*/
public Integer getHeight() {
return height;
}
/**
*
* #param height
* The height
*/
public void setHeight(Integer height) {
this.height = height;
}
/**
*
* #return
* The width
*/
public Integer getWidth() {
return width;
}
/**
*
* #param width
* The width
*/
public void setWidth(Integer width) {
this.width = width;
}
/**
*
* #return
* The type
*/
public String getType() {
return type;
}
/**
*
* #param type
* The type
*/
public void setType(String type) {
this.type = type;
}
/**
*
* #return
* The subtype
*/
public String getSubtype() {
return subtype;
}
/**
*
* #param subtype
* The subtype
*/
public void setSubtype(String subtype) {
this.subtype = subtype;
}
/**
*
* #return
* The caption
*/
public Object getCaption() {
return caption;
}
/**
*
* #param caption
* The caption
*/
public void setCaption(Object caption) {
this.caption = caption;
}
/**
*
* #return
* The copyright
*/
public Object getCopyright() {
return copyright;
}
/**
*
* #param copyright
* The copyright
*/
public void setCopyright(Object copyright) {
this.copyright = copyright;
}
}
I know it's a lot of code to go through but I'm looking for any help to solve this problem so I'm trying to be as clear as I can.
I was able to get a solution by implementing a custom JsonDeserializer and then adding that to the RestAdapter like so:
public class ResultsDeserializerJson implements JsonDeserializer<Result> {
#Override
public Result deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonElement titleElement = json.getAsJsonObject().get("title");
JsonElement multimediaElement = json.getAsJsonObject().get("multimedia");
if (multimediaElement.isJsonArray()) {
return new Result(
titleElement.toString(),
(Multimedia[]) context.deserialize(multimediaElement.getAsJsonArray(), Multimedia[].class));
} else if (multimediaElement.getAsString().equals("")) {
Multimedia multimedia = new Multimedia();
multimedia.setFormat("");
multimedia.setUrl("");
return new Result(titleElement.toString(), multimedia);
} else {
Log.d("ResultsDeserializerJson", multimediaElement.toString());
throw new JsonParseException("Unsupported type of multimedia element");
}
}
}
Inside Result.java I added the following constructor (note you can add more parameters for things like section, subsection, etc.):
public Result(String title, Multimedia ... multimedia) {
this.mTitle = title.replace("\"", "");;
mMultimedia = Arrays.asList(multimedia);
}
Then for my RestAdapter I do the following:
private NYTimesService() {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Result.class, new ResultsDeserializerJson()).create();
mAsyncRestAdapter = new RestAdapter.Builder()
.setEndpoint(API_URL)
.setConverter(new GsonConverter(gson))
.setRequestInterceptor(new RequestInterceptor() {
#Override
public void intercept(RequestFacade request) {
request.addEncodedQueryParam("api-key", API_KEY);
}
})
.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
}
I created a custom application to get this working and the repository is open sourced here:
SampleNYTimesApp Repo
This is still somewhat of a hackish solution, and I feel like it is not the most optimal, but I was able to get the following in the time I figured out the solution:
firstly i have trouble with creating database,then i want to put my received huge json datas(i converted json to java model by GsonBuilder and i saw all the datas in my entity[] list which made from ReceivedEntityModel class) to database,but i failed at first steps.it never creates my columns,so that after insertion there is 0 rowcount:(, i read all those answers about this topic and they didn't help me at all.I'm stuck.Anyone can help??
public void onCreate(SQLiteDatabase db)
{
String CREATE_M_ENTITY_TABLE = "CREATE TABLE " + TABLE_2_NAME + " ("
+ rId + " INTEGER PRIMARY KEY, "
+ ParentId + " INTEGER, "
+ Code+ " INTEGER, "
+ Label + " TEXT, "
+ LabelFL + " TEXT, "
+ EntityGroupId + " INTEGER, "
+ Property + " TEXT, "
+ ReportCode+ " INTEGER, "
+ Description + " TEXT, "
+ Code1Id + " INTEGER, "
+ Code2Id + " INTEGER, "
+ Code3Id + " INTEGER, "
+ Code4Id+ " INTEGER, "
+ Code5Id + " INTEGER, "
+ DefaultDimension1+ " INTEGER, "
+ DefaultDimension2 + "INTEGER, "
+ DefaultDimension3 + " INTEGER, "
+ CompanyId + " INTEGER, "
+ BranchId + " INTEGER, "
+ ReferenceDate + " TEXT, "
+ ResField1+ " TEXT, "
+ ResField2 + " TEXT, "
+ AreaId + " INTEGER, "
+ ModifiedDateTime + " TEXT, "
+ CreatedDateTime + " TEXT, "
+ RecId + " INTEGER, "
+ IsActive + " BIT,"
+ ModifiedBy + " INTEGER,"
+ CreatedBy + " INTEGER" + ") ";
db.execSQL(CREATE_M_ENTITY_TABLE);
}
i call this function at main activity to bind listview
public Cursor fetchEntities()
{
SQLiteDatabase db = dbHelper.getWritableDatabase();
String myQuery="Select Code, Label from entity";
Cursor mCursor=db.rawQuery(myQuery,null);
int rowCount=mCursor.getCount();
//Cursor mCursor = db.query(TABLE_2_NAME, new String[] {Code, Label }, null,null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
//as you see there is paramater like ReceivedEntityModel ,i get the datas from this Model's getters and i want to put them into a database is shown below.
public void AddNewEntity(ReceivedEntityModel[] entity)
{
// addnewentity
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
for (int i = 0; i < entity.length; i++) {
values.put(rId, entity[i].getRId());
values.put(ParentId, entity[i].getParentId());
values.put(Code, entity[i].getCode());
values.put(Label, entity[i].getLabel());
values.put(LabelFL, entity[i].getLabelFL());
values.put(EntityGroupId, entity[i].getEntityGroupId());
values.put(ReportCode, entity[i].getReportCode());
values.put(Description, entity[i].getDescription());
values.put(Code1Id, entity[i].getCode1Id());
values.put(Code2Id, entity[i].getCode2Id());
values.put(Code3Id, entity[i].getCode3Id());
values.put(Code4Id, entity[i].getCode4Id());
values.put(Code5Id, entity[i].getCode5Id());
values.put(DefaultDimension1, entity[i].getDefaultDimension1Id());
values.put(DefaultDimension2, entity[i].getDefaultDimension2Id());
values.put(DefaultDimension3, entity[i].getDefaultDimension3Id());
values.put(CompanyId, entity[i].getCompanyId());
values.put(BranchId, entity[i].getBranchId());
values.put(ReferenceDate, entity[i].getReferenceDate());
values.put(ResField1, (String) entity[i].getResField1());
values.put(ResField2, (String) entity[i].getResField2());
values.put(AreaId, entity[i].getAreaId());
values.put(ModifiedDateTime, entity[i].getModifiedDateTime());
values.put(CreatedDateTime, entity[i].getCreatedDateTime());
values.put(RecId, entity[i].getRecId());
values.put(IsActive, entity[i].getIsActive());
values.put(ModifiedBy, entity[i].getModifiedBy());
values.put(CreatedBy, (String) entity[i].getCreatedBy());
}
db.insert(TABLE_2_NAME, null, values);
db.close();
}
this is Setup.java,fetchEntities(),AddNewEntity() functions are calling from there.Gson Builder make me a model.And the i call AddNewEntity()
protected String doInBackground(String... urls) {
entityReqestInfo = new EntityReqestInfo();
String cevap = POST_FOR_ENTITY(urls[0], entityReqestInfo);
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
receivedEM = gson.fromJson(cevap, ReceivedEntityModel[].class);
myDB.getDatabaseEntityOperations().AddNewEntity(receivedEM);
pDialog.cancel();
return cevap;
}
and last of all my generated entity Model ReceivedEntityModel class
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ReceivedEntityModel {
private Integer rId;
private Integer ParentId;
private String Code;
private String Label;
private String LabelFL;
private Integer EntityGroupId;
private String Property;
private String ReportCode;
private String Description;
private Integer Code1Id;
private Integer Code2Id;
private Integer Code3Id;
private Integer Code4Id;
private Integer Code5Id;
private Integer DefaultDimension1Id;
private Integer DefaultDimension2Id;
private Integer DefaultDimension3Id;
private Integer CompanyId;
private Integer BranchId;
private String ReferenceDate;
private String ResField1;
private String ResField2;
private String AreaId;
private String ModifiedDateTime;
private String CreatedDateTime;
private Integer RecId;
private Boolean IsActive;
private Integer ModifiedBy;
private String CreatedBy;
private String DBranch;
private String DCompany;
private String MEntityGroup;
private List<String> MEntityTableModule = new ArrayList<String>();
private Map<String, String> additionalProperties = new HashMap<String, String>();
/**
*
* #return The rId
*/
public Integer getRId() {
return rId;
}
/**
*
* #param rId
* The rId
*/
public void setRId(Integer rId) {
this.rId = rId;
}
public ReceivedEntityModel withRId(Integer rId) {
this.rId = rId;
return this;
}
/**
*
* #return The ParentId
*/
public Integer getParentId() {
return ParentId;
}
/**
*
* #param ParentId
* The ParentId
*/
public void setParentId(Integer ParentId) {
this.ParentId = ParentId;
}
public ReceivedEntityModel withParentId(Integer ParentId) {
this.ParentId = ParentId;
return this;
}
/**
*
* #return The Code
*/
public String getCode() {
return Code;
}
/**
*
* #param Code
* The Code
*/
public void setCode(String Code) {
this.Code = Code;
}
public ReceivedEntityModel withCode(String Code) {
this.Code = Code;
return this;
}
/**
*
* #return The Label
*/
public String getLabel() {
return Label;
}
/**
*
* #param Label
* The Label
*/
public void setLabel(String Label) {
this.Label = Label;
}
public ReceivedEntityModel withLabel(String Label) {
this.Label = Label;
return this;
}
/**
*
* #return The LabelFL
*/
public String getLabelFL() {
return LabelFL;
}
/**
*
* #param LabelFL
* The LabelFL
*/
public void setLabelFL(String LabelFL) {
this.LabelFL = LabelFL;
}
public ReceivedEntityModel withLabelFL(String LabelFL) {
this.LabelFL = LabelFL;
return this;
}
/**
*
* #return The EntityGroupId
*/
public Integer getEntityGroupId() {
return EntityGroupId;
}
/**
*
* #param EntityGroupId
* The EntityGroupId
*/
public void setEntityGroupId(Integer EntityGroupId) {
this.EntityGroupId = EntityGroupId;
}
public ReceivedEntityModel withEntityGroupId(Integer EntityGroupId) {
this.EntityGroupId = EntityGroupId;
return this;
}
/**
*
* #return The Property
*/
public String getProperty() {
return Property;
}
/**
*
* #param Property
* The Property
*/
public void setProperty(String Property) {
this.Property = Property;
}
public ReceivedEntityModel withProperty(String Property) {
this.Property = Property;
return this;
}
/**
*
* #return The ReportCode
*/
public String getReportCode() {
return ReportCode;
}
/**
*
* #param ReportCode
* The ReportCode
*/
public void setReportCode(String ReportCode) {
this.ReportCode = ReportCode;
}
public ReceivedEntityModel withReportCode(String ReportCode) {
this.ReportCode = ReportCode;
return this;
}
/**
*
* #return The Description
*/
public String getDescription() {
return Description;
}
/**
*
* #param Description
* The Description
*/
public void setDescription(String Description) {
this.Description = Description;
}
public ReceivedEntityModel withDescription(String Description) {
this.Description = Description;
return this;
}
/**
*
* #return The Code1Id
*/
public Integer getCode1Id() {
return Code1Id;
}
/**
*
* #param Code1Id
* The Code1Id
*/
public void setCode1Id(Integer Code1Id) {
this.Code1Id = Code1Id;
}
public ReceivedEntityModel withCode1Id(Integer Code1Id) {
this.Code1Id = Code1Id;
return this;
}
/**
*
* #return The Code2Id
*/
public Integer getCode2Id() {
return Code2Id;
}
/**
*
* #param Code2Id
* The Code2Id
*/
public void setCode2Id(Integer Code2Id) {
this.Code2Id = Code2Id;
}
public ReceivedEntityModel withCode2Id(Integer Code2Id) {
this.Code2Id = Code2Id;
return this;
}
/**
*
* #return The Code3Id
*/
public Integer getCode3Id() {
return Code3Id;
}
/**
*
* #param Code3Id
* The Code3Id
*/
public void setCode3Id(Integer Code3Id) {
this.Code3Id = Code3Id;
}
public ReceivedEntityModel withCode3Id(Integer Code3Id) {
this.Code3Id = Code3Id;
return this;
}
/**
*
* #return The Code4Id
*/
public Integer getCode4Id() {
return Code4Id;
}
/**
*
* #param Code4Id
* The Code4Id
*/
public void setCode4Id(Integer Code4Id) {
this.Code4Id = Code4Id;
}
public ReceivedEntityModel withCode4Id(Integer Code4Id) {
this.Code4Id = Code4Id;
return this;
}
/**
*
* #return The Code5Id
*/
public Integer getCode5Id() {
return Code5Id;
}
/**
*
* #param Code5Id
* The Code5Id
*/
public void setCode5Id(Integer Code5Id) {
this.Code5Id = Code5Id;
}
public ReceivedEntityModel withCode5Id(Integer Code5Id) {
this.Code5Id = Code5Id;
return this;
}
/**
*
* #return The DefaultDimension1Id
*/
public Integer getDefaultDimension1Id() {
return DefaultDimension1Id;
}
/**
*
* #param DefaultDimension1Id
* The DefaultDimension1Id
*/
public void setDefaultDimension1Id(Integer DefaultDimension1Id) {
this.DefaultDimension1Id = DefaultDimension1Id;
}
public ReceivedEntityModel withDefaultDimension1Id(
Integer DefaultDimension1Id) {
this.DefaultDimension1Id = DefaultDimension1Id;
return this;
}
/**
*
* #return The DefaultDimension2Id
*/
public Integer getDefaultDimension2Id() {
return DefaultDimension2Id;
}
/**
*
* #param DefaultDimension2Id
* The DefaultDimension2Id
*/
public void setDefaultDimension2Id(Integer DefaultDimension2Id) {
this.DefaultDimension2Id = DefaultDimension2Id;
}
public ReceivedEntityModel withDefaultDimension2Id(
Integer DefaultDimension2Id) {
this.DefaultDimension2Id = DefaultDimension2Id;
return this;
}
/**
*
* #return The DefaultDimension3Id
*/
public Integer getDefaultDimension3Id() {
return DefaultDimension3Id;
}
/**
*
* #param DefaultDimension3Id
* The DefaultDimension3Id
*/
public void setDefaultDimension3Id(Integer DefaultDimension3Id) {
this.DefaultDimension3Id = DefaultDimension3Id;
}
public ReceivedEntityModel withDefaultDimension3Id(
Integer DefaultDimension3Id) {
this.DefaultDimension3Id = DefaultDimension3Id;
return this;
}
/**
*
* #return The CompanyId
*/
public Integer getCompanyId() {
return CompanyId;
}
/**
*
* #param CompanyId
* The CompanyId
*/
public void setCompanyId(Integer CompanyId) {
this.CompanyId = CompanyId;
}
public ReceivedEntityModel withCompanyId(Integer CompanyId) {
this.CompanyId = CompanyId;
return this;
}
/**
*
* #return The BranchId
*/
public Integer getBranchId() {
return BranchId;
}
/**
*
* #param BranchId
* The BranchId
*/
public void setBranchId(Integer BranchId) {
this.BranchId = BranchId;
}
public ReceivedEntityModel withBranchId(Integer BranchId) {
this.BranchId = BranchId;
return this;
}
/**
*
* #return The ReferenceDate
*/
public String getReferenceDate() {
return ReferenceDate;
}
/**
*
* #param ReferenceDate
* The ReferenceDate
*/
public void setReferenceDate(String ReferenceDate) {
this.ReferenceDate = ReferenceDate;
}
public ReceivedEntityModel withReferenceDate(String ReferenceDate) {
this.ReferenceDate = ReferenceDate;
return this;
}
/**
*
* #return The ResField1
*/
public String getResField1() {
return ResField1;
}
/**
*
* #param ResField1
* The ResField1
*/
public void setResField1(String ResField1) {
this.ResField1 = ResField1;
}
public ReceivedEntityModel withResField1(String ResField1) {
this.ResField1 = ResField1;
return this;
}
/**
*
* #return The ResField2
*/
public String getResField2() {
return ResField2;
}
/**
*
* #param ResField2
* The ResField2
*/
public void setResField2(String ResField2) {
this.ResField2 = ResField2;
}
public ReceivedEntityModel withResField2(String ResField2) {
this.ResField2 = ResField2;
return this;
}
/**
*
* #return The AreaId
*/
public String getAreaId() {
return AreaId;
}
/**
*
* #param AreaId
* The AreaId
*/
public void setAreaId(String AreaId) {
this.AreaId = AreaId;
}
public ReceivedEntityModel withAreaId(String AreaId) {
this.AreaId = AreaId;
return this;
}
/**
*
* #return The ModifiedDateTime
*/
public String getModifiedDateTime() {
return ModifiedDateTime;
}
/**
*
* #param ModifiedDateTime
* The ModifiedDateTime
*/
public void setModifiedDateTime(String ModifiedDateTime) {
this.ModifiedDateTime = ModifiedDateTime;
}
public ReceivedEntityModel withModifiedDateTime(String ModifiedDateTime) {
this.ModifiedDateTime = ModifiedDateTime;
return this;
}
/**
*
* #return The CreatedDateTime
*/
public String getCreatedDateTime() {
return CreatedDateTime;
}
/**
*
* #param CreatedDateTime
* The CreatedDateTime
*/
public void setCreatedDateTime(String CreatedDateTime) {
this.CreatedDateTime = CreatedDateTime;
}
public ReceivedEntityModel withCreatedDateTime(String CreatedDateTime) {
this.CreatedDateTime = CreatedDateTime;
return this;
}
/**
*
* #return The RecId
*/
public Integer getRecId() {
return RecId;
}
/**
*
* #param RecId
* The RecId
*/
public void setRecId(Integer RecId) {
this.RecId = RecId;
}
public ReceivedEntityModel withRecId(Integer RecId) {
this.RecId = RecId;
return this;
}
/**
*
* #return The IsActive
*/
public Boolean getIsActive() {
return IsActive;
}
/**
*
* #param IsActive
* The IsActive
*/
public void setIsActive(Boolean IsActive) {
this.IsActive = IsActive;
}
public ReceivedEntityModel withIsActive(Boolean IsActive) {
this.IsActive = IsActive;
return this;
}
/**
*
* #return The ModifiedBy
*/
public Integer getModifiedBy() {
return ModifiedBy;
}
/**
*
* #param ModifiedBy
* The ModifiedBy
*/
public void setModifiedBy(Integer ModifiedBy) {
this.ModifiedBy = ModifiedBy;
}
public ReceivedEntityModel withModifiedBy(Integer ModifiedBy) {
this.ModifiedBy = ModifiedBy;
return this;
}
/**
*
* #return The CreatedBy
*/
public String getCreatedBy() {
return CreatedBy;
}
/**
*
* #param CreatedBy
* The CreatedBy
*/
public void setCreatedBy(String CreatedBy) {
this.CreatedBy = CreatedBy;
}
public ReceivedEntityModel withCreatedBy(String CreatedBy) {
this.CreatedBy = CreatedBy;
return this;
}
/**
*
* #return The DBranch
*/
public String getDBranch() {
return DBranch;
}
/**
*
* #param DBranch
* The D_Branch
*/
public void setDBranch(String DBranch) {
this.DBranch = DBranch;
}
public ReceivedEntityModel withDBranch(String DBranch) {
this.DBranch = DBranch;
return this;
}
/**
*
* #return The DCompany
*/
public String getDCompany() {
return DCompany;
}
/**
*
* #param DCompany
* The D_Company
*/
public void setDCompany(String DCompany) {
this.DCompany = DCompany;
}
public ReceivedEntityModel withDCompany(String DCompany) {
this.DCompany = DCompany;
return this;
}
/**
*
* #return The MEntityGroup
*/
public String getMEntityGroup() {
return MEntityGroup;
}
/**
*
* #param MEntityGroup
* The M_EntityGroup
*/
public void setMEntityGroup(String MEntityGroup) {
this.MEntityGroup = MEntityGroup;
}
public ReceivedEntityModel withMEntityGroup(String MEntityGroup) {
this.MEntityGroup = MEntityGroup;
return this;
}
/**
*
* #return The MEntityTableModule
*/
public List<String> getMEntityTableModule() {
return MEntityTableModule;
}
/**
*
* #param MEntityTableModule
* The M_EntityTableModule
*/
public void setMEntityTableModule(List<String> MEntityTableModule) {
this.MEntityTableModule = MEntityTableModule;
}
public ReceivedEntityModel withMEntityTableModule(
List<String> MEntityTableModule) {
this.MEntityTableModule = MEntityTableModule;
return this;
}
public Map<String, String> getAdditionalProperties() {
return this.additionalProperties;
}
public void setAdditionalProperty(String name, String value) {
this.additionalProperties.put(name, value);
}
public ReceivedEntityModel withAdditionalProperty(String name, String value) {
this.additionalProperties.put(name, value);
return this;
}
}
Where are the column names defined?
The DefaultDimension2 column is not created with the intended name
in your table, because you forgot a space here:
+ DefaultDimension2 + "INTEGER, "
It must be
+ DefaultDimension2 + " INTEGER, "
So, supposing that the DefaultDimension2 column name is defined as
public String DefaultDimension2 = "DefaultDimension2";
it is actually created as "DefaultDimension2INTEGER, " instead of "DefaultDimension2 INTEGER, "
It's really a common mistake, mostly due to hurry.