Skip to content

Commit

Permalink
fix: EntriesModel parsing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikram Kalta authored and Vikram Kalta committed Nov 28, 2024
1 parent 2a561bf commit 148fd23
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.contentstack.sdk</groupId>
<artifactId>java</artifactId>
<version>2.0.1</version>
<version>2.0.2</version>
<packaging>jar</packaging>
<name>contentstack-java</name>
<description>Java SDK for Contentstack Content Delivery API</description>
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/com/contentstack/sdk/EntriesModel.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.contentstack.sdk;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -18,13 +18,14 @@ protected EntriesModel(JSONObject responseJSON) {
this.jsonObject = responseJSON;
objectList = new ArrayList<>();
Object entryList = jsonObject.opt("entries");
if (entryList instanceof JSONArray) {
JSONArray entries = (JSONArray) entryList;
if (entries.length() > 0) {
if (entryList instanceof ArrayList) {
ArrayList<LinkedHashMap> entries = (ArrayList) entryList;
if (!entries.isEmpty()) {
entries.forEach(model -> {
if (model instanceof JSONObject) {
JSONObject newModel = (JSONObject) model;
EntryModel entry = new EntryModel(newModel);
if (model instanceof LinkedHashMap) {
// Convert LinkedHashMap to JSONObject
JSONObject jsonModel = new JSONObject((LinkedHashMap<?, ?>) model);
EntryModel entry = new EntryModel(jsonModel);
objectList.add(entry);
}
});
Expand Down

0 comments on commit 148fd23

Please sign in to comment.