René's URL Explorer Experiment


Title: SyncStack.setJSON skips single item in "items" array · Issue #183 · contentstack/contentstack-java · GitHub

Open Graph Title: SyncStack.setJSON skips single item in "items" array · Issue #183 · contentstack/contentstack-java

X Title: SyncStack.setJSON skips single item in "items" array · Issue #183 · contentstack/contentstack-java

Description: Description: The SyncStack.setJSON method is incorrectly handling scenarios where the "items" key in the provided JSONObject contains a single item. Instead of processing this single item, the current logic within the else block (when it...

Open Graph Description: Description: The SyncStack.setJSON method is incorrectly handling scenarios where the "items" key in the provided JSONObject contains a single item. Instead of processing this single item, the curr...

X Description: Description: The SyncStack.setJSON method is incorrectly handling scenarios where the "items" key in the provided JSONObject contains a single item. Instead of processing this single item...

Opengraph URL: https://github.com/contentstack/contentstack-java/issues/183

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SyncStack.setJSON skips single item in \"items\" array","articleBody":"**Description:**\nThe [**SyncStack.setJSON** method ](https://github.com/contentstack/contentstack-java/blob/master/src/main/java/com/contentstack/sdk/SyncStack.java#L62C5-L86C10) is incorrectly handling scenarios where the \"**items**\" key in the provided JSONObject contains a single item.\nInstead of processing this single item, the current logic within the else block (when itemsObj is not a JSONArray) logs a warning and initializes an empty syncItems list, effectively skipping the data.\n\n**Code Snippet:**\n```java\nprotected synchronized void setJSON(@NotNull JSONObject jsonobject) {\n    if (jsonobject == null) {\n        throw new IllegalArgumentException(\"JSON object cannot be null.\");\n    }\n\n    this.receiveJson = jsonobject;\n\n    if (receiveJson.has(\"items\")) {\n        Object itemsObj = receiveJson.opt(\"items\");\n        if (itemsObj instanceof JSONArray) {\n            JSONArray jsonArray = (JSONArray) itemsObj;\n            syncItems = new ArrayList\u003c\u003e();\n            for (int i = 0; i \u003c jsonArray.length(); i++) {\n                JSONObject jsonItem = jsonArray.optJSONObject(i);\n                if (jsonItem != null) {\n                    syncItems.add(sanitizeJson(jsonItem));\n                }\n            }\n        } else {\n            logger.warning(\"'items' is not a valid list. Skipping processing.\"); // ✅ Prevent crashes\n            syncItems = new ArrayList\u003c\u003e();\n        }\n    } else {\n        syncItems = new ArrayList\u003c\u003e();\n    }\n}\n```\n\n**Observed Behavior:**\n\nWhen the \"items\" key in the receiveJson JSONObject contains a single JSON object (not a JSONArray of one element), the code enters the else block and skips processing this item. The syncItems list remains empty in this case.\n\n**Expected Behavior:**\n\nWhen the \"items\" key contains only a single JSON object, it should be treated as a single item to be processed and added to the syncItems list.\n\n**Suggested Solution:**\n\nThe else block should be modified to handle the case where itemsObj is a single JSONObject. A possible solution would be to check if itemsObj is an instance of JSONObject and, if so, create a new ArrayList, add the sanitized itemsObj to it, and assign it to syncItems.\n\n```java\n        } else {\n            if (itemsObj instanceof JSONObject) {\n                syncItems = new ArrayList\u003c\u003e();\n                syncItems.add(sanitizeJson((JSONObject) itemsObj));\n            } else {\n                logger.warning(\"'items' is not a valid list. Skipping processing.\"); // ✅ Prevent crashes\n                syncItems = new ArrayList\u003c\u003e();\n            }\n        }\n```\n\n**Impact:**\n\nThis issue leads to data loss or incomplete synchronization when the \"items\" payload from Contentstack contains a single entry. As there is any exception thrown, we consider the execution as completed, and we are updating the sync token, which leads to data loss.\n\n![Image](https://github.com/user-attachments/assets/877214da-5fcf-4ef4-86d7-52e9521725f7)","author":{"url":"https://github.com/victor-pariente-edo","@type":"Person","name":"victor-pariente-edo"},"datePublished":"2025-04-21T15:09:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/183/contentstack-java/issues/183"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:602fb62a-2002-083a-af79-4ea94191d9c0
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8E26:CD22B:148DE18:19ED7E2:697F2740
html-safe-nonce8a89c232af46e3edf1387dfb62e3b95d58f00e88218a2d18b65a5d98ce665fb5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTI2OkNEMjJCOjE0OERFMTg6MTlFRDdFMjo2OTdGMjc0MCIsInZpc2l0b3JfaWQiOiIyMjc1MjQ5MDY5ODc1OTk2NDgwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacf14fd1334af689a4972c179d630010444a0d67c73265cb5c4c887def49db7566
hovercard-subject-tagissue:3008636460
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/contentstack/contentstack-java/183/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c5c6c1022e6d266804e9d047c26ffbb2ab056804c2543f09511f0a950cb16ffa/contentstack/contentstack-java/issues/183
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c5c6c1022e6d266804e9d047c26ffbb2ab056804c2543f09511f0a950cb16ffa/contentstack/contentstack-java/issues/183
og:image:altDescription: The SyncStack.setJSON method is incorrectly handling scenarios where the "items" key in the provided JSONObject contains a single item. Instead of processing this single item, the curr...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamevictor-pariente-edo
hostnamegithub.com
expected-hostnamegithub.com
None60279d4097367e16897439d16d6bbe4180663db828c666eeed2656988ffe59f6
turbo-cache-controlno-preview
go-importgithub.com/contentstack/contentstack-java git https://github.com/contentstack/contentstack-java.git
octolytics-dimension-user_id24450751
octolytics-dimension-user_logincontentstack
octolytics-dimension-repository_id106927781
octolytics-dimension-repository_nwocontentstack/contentstack-java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id106927781
octolytics-dimension-repository_network_root_nwocontentstack/contentstack-java
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7c85641c598ad130c74f7bcc27f58575cac69551
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/contentstack/contentstack-java/issues/183#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcontentstack%2Fcontentstack-java%2Fissues%2F183
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcontentstack%2Fcontentstack-java%2Fissues%2F183
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=contentstack%2Fcontentstack-java
Reloadhttps://github.com/contentstack/contentstack-java/issues/183
Reloadhttps://github.com/contentstack/contentstack-java/issues/183
Reloadhttps://github.com/contentstack/contentstack-java/issues/183
contentstack https://github.com/contentstack
contentstack-javahttps://github.com/contentstack/contentstack-java
Notifications https://github.com/login?return_to=%2Fcontentstack%2Fcontentstack-java
Fork 3 https://github.com/login?return_to=%2Fcontentstack%2Fcontentstack-java
Star 4 https://github.com/login?return_to=%2Fcontentstack%2Fcontentstack-java
Code https://github.com/contentstack/contentstack-java
Issues 0 https://github.com/contentstack/contentstack-java/issues
Pull requests 5 https://github.com/contentstack/contentstack-java/pulls
Actions https://github.com/contentstack/contentstack-java/actions
Projects 0 https://github.com/contentstack/contentstack-java/projects
Security 0 https://github.com/contentstack/contentstack-java/security
Insights https://github.com/contentstack/contentstack-java/pulse
Code https://github.com/contentstack/contentstack-java
Issues https://github.com/contentstack/contentstack-java/issues
Pull requests https://github.com/contentstack/contentstack-java/pulls
Actions https://github.com/contentstack/contentstack-java/actions
Projects https://github.com/contentstack/contentstack-java/projects
Security https://github.com/contentstack/contentstack-java/security
Insights https://github.com/contentstack/contentstack-java/pulse
New issuehttps://github.com/login?return_to=https://github.com/contentstack/contentstack-java/issues/183
New issuehttps://github.com/login?return_to=https://github.com/contentstack/contentstack-java/issues/183
SyncStack.setJSON skips single item in "items" arrayhttps://github.com/contentstack/contentstack-java/issues/183#top
https://github.com/victor-pariente-edo
https://github.com/victor-pariente-edo
victor-pariente-edohttps://github.com/victor-pariente-edo
on Apr 21, 2025https://github.com/contentstack/contentstack-java/issues/183#issue-3008636460
SyncStack.setJSON method https://github.com/contentstack/contentstack-java/blob/master/src/main/java/com/contentstack/sdk/SyncStack.java#L62C5-L86C10
https://private-user-images.githubusercontent.com/147144294/435711931-877214da-5fcf-4ef4-86d7-52e9521725f7.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njk5NDExMDAsIm5iZiI6MTc2OTk0MDgwMCwicGF0aCI6Ii8xNDcxNDQyOTQvNDM1NzExOTMxLTg3NzIxNGRhLTVmY2YtNGVmNC04NmQ3LTUyZTk1MjE3MjVmNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwMjAxJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDIwMVQxMDEzMjBaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT03YzY4MTEzOGRiZWEyNTBiYWQ4MmFkYTBlMmFkYjkwNGI4OTMwZGZhNTBjYzc4ZDJlY2NlNDgwY2VlN2M4NzYxJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.4cHt44WXN8A_3FX_BeHRf-7IYkPgAUccTrQIJsrIp1o
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.