Skip to content

Commit 072e180

Browse files
Merge pull request #224 from contentstack/staging
DX | 25-08-2025 | Release
2 parents e469599 + 389820f commit 072e180

File tree

11 files changed

+203
-10
lines changed

11 files changed

+203
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## v2.2.0
4+
5+
### Date: 25-Aug-2025
6+
7+
- POJO implementation added
8+
39
## v2.1.3
410

511
### Date: 06-Jun-2025

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.contentstack.sdk</groupId>
77
<artifactId>java</artifactId>
8-
<version>2.1.3</version>
8+
<version>2.2.0</version>
99
<packaging>jar</packaging>
1010
<name>contentstack-java</name>
1111
<description>Java SDK for Contentstack Content Delivery API</description>
@@ -22,7 +22,7 @@
2222
<dotenv-source.version>3.0.0</dotenv-source.version>
2323
<rxjava-source.version>3.1.10</rxjava-source.version>
2424
<retrofit-source.version>2.11.0</retrofit-source.version>
25-
<loggin.version>4.12.0</loggin.version>
25+
<loggin.version>5.1.0</loggin.version>
2626
<jococo-plugin.version>0.8.5</jococo-plugin.version>
2727
<lombok-source.version>1.18.36</lombok-source.version>
2828
<junit-jupiter.version>5.11.4</junit-jupiter.version>
@@ -184,7 +184,7 @@
184184
<dependency>
185185
<groupId>com.slack.api</groupId>
186186
<artifactId>bolt</artifactId>
187-
<version>1.44.0</version>
187+
<version>1.45.3</version>
188188
</dependency>
189189
<dependency>
190190
<groupId>org.jetbrains</groupId>
@@ -194,12 +194,12 @@
194194
<dependency>
195195
<groupId>com.squareup.okhttp3</groupId>
196196
<artifactId>okhttp</artifactId>
197-
<version>4.12.0</version>
197+
<version>5.1.0</version>
198198
</dependency>
199199
<dependency>
200200
<groupId>org.slf4j</groupId>
201201
<artifactId>slf4j-simple</artifactId>
202-
<version>1.7.36</version>
202+
<version>2.0.17</version>
203203
</dependency>
204204
<!-- https://mvnrepository.com/artifact/io.github.cdimascio/java-dotenv -->
205205
<dependency>

src/main/java/com/contentstack/sdk/Asset.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.jetbrains.annotations.NotNull;
44
import org.json.JSONObject;
55
import retrofit2.Retrofit;
6+
import lombok.Getter;
7+
import lombok.Setter;
68

79
import java.util.Calendar;
810
import java.util.HashMap;
@@ -29,6 +31,8 @@
2931
* @version 1.0.0
3032
* @since 01-11-2017
3133
*/
34+
@Getter
35+
@Setter
3236
public class Asset {
3337

3438
protected static final Logger logger = Logger.getLogger(Asset.class.getSimpleName());

src/main/java/com/contentstack/sdk/AssetModel.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
import java.util.LinkedHashMap;
44
import org.json.JSONArray;
55
import org.json.JSONObject;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
import lombok.NoArgsConstructor;
69

710

811
/**
912
* The type Asset model.
1013
*/
14+
@Getter
15+
@Setter
16+
@NoArgsConstructor
1117
class AssetModel {
1218

1319
String uploadedUid;

src/main/java/com/contentstack/sdk/AssetsModel.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55

66
import org.json.JSONArray;
77
import org.json.JSONObject;
8+
import lombok.Getter;
9+
import lombok.Setter;
10+
import lombok.NoArgsConstructor;
811

912
/**
1013
* The type Assets model.
1114
*/
15+
@Getter
16+
@Setter
17+
@NoArgsConstructor
1218
class AssetsModel {
1319

1420
List<Object> objects = new ArrayList<>();

src/main/java/com/contentstack/sdk/ContentType.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import org.jetbrains.annotations.NotNull;
44
import org.json.JSONObject;
5-
5+
import org.json.JSONArray;
6+
import lombok.Getter;
7+
import lombok.Setter;
68
import java.util.HashMap;
79
import java.util.Iterator;
810
import java.util.LinkedHashMap;
@@ -20,13 +22,23 @@
2022
* @version 1.0.0
2123
* @since 01-11-2017
2224
*/
25+
26+
@Getter
27+
@Setter
2328
public class ContentType {
2429

2530
protected static final Logger logger = Logger.getLogger(ContentType.class.getSimpleName());
2631
protected String contentTypeUid;
2732
protected Stack stackInstance = null;
2833
protected LinkedHashMap<String, Object> headers = null;
2934

35+
// NEW: Content type data fields for POJO access (public for Lombok-generated getters)
36+
public String title;
37+
public String description;
38+
public String uid;
39+
public JSONArray schema;
40+
public JSONObject contentTypeData;
41+
3042
protected ContentType() throws IllegalAccessException {
3143
throw new IllegalAccessException("Can Not Access Private Modifier");
3244
}
@@ -156,7 +168,17 @@ private void fetchContentTypes(String urlString, JSONObject params, HashMap<Stri
156168
if (callback != null) {
157169
HashMap<String, Object> urlParams = getUrlParams(params);
158170
new CSBackgroundTask(this, stackInstance, Constants.FETCHCONTENTTYPES, urlString, headers, urlParams,
159-
Constants.REQUEST_CONTROLLER.CONTENTTYPES.toString(), callback);
171+
// Constants.REQUEST_CONTROLLER.CONTENTTYPES.toString(), callback);
172+
Constants.REQUEST_CONTROLLER.CONTENTTYPES.toString(), new ContentTypesCallback() {
173+
@Override
174+
public void onCompletion(ContentTypesModel model, Error error) {
175+
if (error == null) {
176+
// NEW: Store content type data in this instance for POJO access
177+
model.setContentTypeData(ContentType.this);
178+
}
179+
callback.onCompletion(model, error);
180+
}
181+
});
160182
}
161183
}
162184

@@ -173,4 +195,20 @@ private HashMap<String, Object> getUrlParams(JSONObject urlQueriesJSON) {
173195
return hashMap;
174196
}
175197

198+
/**
199+
* Set content type data from JSON response.
200+
* This method is called internally by ContentTypesModel.
201+
*
202+
* @param ctData the content type data JSONObject
203+
*/
204+
protected void setContentTypeData(JSONObject ctData) {
205+
if (ctData != null) {
206+
this.title = ctData.optString("title");
207+
this.description = ctData.optString("description");
208+
this.uid = ctData.optString("uid");
209+
this.schema = ctData.optJSONArray("schema");
210+
this.contentTypeData = ctData;
211+
}
212+
}
213+
176214
}

src/main/java/com/contentstack/sdk/ContentTypesModel.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
import java.util.List;
66
import org.json.JSONArray;
77
import org.json.JSONObject;
8+
import lombok.Getter;
9+
import lombok.Setter;
10+
import lombok.NoArgsConstructor;
811

912

1013

1114
/**
1215
* The ContentTypesModel that contains content type response
1316
*/
17+
@Getter
18+
@Setter
19+
@NoArgsConstructor
1420
public class ContentTypesModel {
1521

1622
private Object response;
@@ -58,4 +64,17 @@ public Object getResponse() {
5864
public JSONArray getResultArray() {
5965
return responseJSONArray;
6066
}
67+
68+
/**
69+
* Set content type data in the ContentType instance for POJO access.
70+
* This method is called internally after fetching content type data.
71+
*
72+
* @param contentType the ContentType instance to set data in
73+
*/
74+
public void setContentTypeData(ContentType contentType) {
75+
if (response instanceof JSONObject) {
76+
JSONObject ctData = (JSONObject) response;
77+
contentType.setContentTypeData(ctData);
78+
}
79+
}
6180
}

src/main/java/com/contentstack/sdk/EntryModel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
import java.util.Map;
55
import org.json.JSONArray;
66
import org.json.JSONObject;
7+
import lombok.Getter;
8+
import lombok.Setter;
79

810

11+
@Getter
12+
@Setter
913
class EntryModel {
1014

1115
private static final String PUBLISH_DETAIL_KEY = "publish_details";

src/test/java/com/contentstack/sdk/TestAsset.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,42 @@ void testAssetIncludeOwner() {
189189
Assertions.assertTrue(asset.urlQueries.has("include_metadata"));
190190
}
191191

192+
// @Test
193+
// void testAssetAsPOJO() {
194+
// Asset asset = stack.asset(assetUid);
195+
// asset.fetch(new FetchResultCallback() {
196+
// @Override
197+
// public void onCompletion(ResponseType responseType, Error error) {
198+
// if (error == null) {
199+
// Assertions.assertNotNull(asset.getAssetUid());
200+
// Assertions.assertNotNull(asset.getFileType());
201+
// Assertions.assertNotNull(asset.getFileSize());
202+
// Assertions.assertNotNull(asset.getFileName());
203+
// Assertions.assertNotNull(asset.getUrl());
204+
// Assertions.assertNotNull(asset.getTags());
205+
// Assertions.assertNotNull(asset.toJSON());
206+
// }
207+
// }
208+
// });
209+
// }
210+
211+
// @Test
212+
// void testAssetTypeSafety() {
213+
// Asset asset = stack.asset(assetUid);
214+
// asset.fetch(new FetchResultCallback() {
215+
// @Override
216+
// public void onCompletion(ResponseType responseType, Error error) {
217+
// if (error == null) {
218+
// Assertions.assertNotNull(asset.getAssetUid());
219+
// Assertions.assertNotNull(asset.getFileType());
220+
// Assertions.assertNotNull(asset.getFileSize());
221+
// Assertions.assertNotNull(asset.getFileName());
222+
// Assertions.assertNotNull(asset.getUrl());
223+
// Assertions.assertNotNull(asset.getTags());
224+
225+
// }
226+
// }
227+
// });
228+
// }
229+
192230
}

src/test/java/com/contentstack/sdk/TestContentType.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,35 @@ public void onCompletion(ContentTypesModel model, Error error) {
9797
});
9898
}
9999

100+
@Test
101+
void testContentTypeAsPOJO() {
102+
ContentType contentType = stack.contentType("product");
103+
Assertions.assertNotNull(contentType.contentTypeUid);
104+
Assertions.assertNotNull(contentType);
105+
106+
Entry entry = contentType.entry("test-entry-uid");
107+
Query query = contentType.query();
108+
Assertions.assertNotNull(entry);
109+
Assertions.assertNotNull(query);
110+
Assertions.assertEquals("product", entry.getContentType());
111+
Assertions.assertEquals("product", query.getContentType());
112+
}
113+
114+
@Test
115+
void testContentTypePOJODataAccess() throws IllegalAccessException {
116+
ContentType contentType = stack.contentType("product");
117+
JSONObject paramObj = new JSONObject();
118+
paramObj.put("include_schema", "true");
119+
contentType.fetch(paramObj, new ContentTypesCallback() {
120+
@Override
121+
public void onCompletion(ContentTypesModel model, Error error) {
122+
if (error == null) {
123+
Assertions.assertNotNull(contentType.contentTypeUid);
124+
Assertions.assertNotNull(contentType);
125+
}
126+
}
127+
});
128+
}
129+
100130

101131
}

0 commit comments

Comments
 (0)