Skip to content

Commit 63f2002

Browse files
committed
json-simple to json migration
1 parent f3118d7 commit 63f2002

File tree

79 files changed

+532
-441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+532
-441
lines changed

g11n-ws/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ subprojects{
5757
cacheApiVersion='1.1.1'
5858
hsqlVersion = '2.3.3'
5959
junitVersion = '4.13.2'
60-
jsonSimpleVersion = '1.1.1'
60+
jsonVersion = '20250107'
6161
commonsCollectionsVersion = '3.2.2'
6262
commonsLangVersion = '3.12.0'
6363
commonsIoVersion = '2.17.0'

g11n-ws/modules/md-data-api-mt/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies {
2525
compileOnly("commons-collections:commons-collections:$commonsCollectionsVersion")
2626
compileOnly("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
2727
compileOnly("org.apache.commons:commons-lang3:$commonsLangVersion")
28-
compileOnly("com.googlecode.json-simple:json-simple:$jsonSimpleVersion"){
28+
compileOnly("org.json:json:$jsonVersion"){
2929
exclude group: 'junit'
3030
}
3131

g11n-ws/modules/md-restful-api-i18n/src/main/java/com/vmware/vip/core/except/ExceptionHandle.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 VMware, Inc.
2+
* Copyright 2019-2025 VMware, Inc.
33
* SPDX-License-Identifier: EPL-2.0
44
*/
55
package com.vmware.vip.core.except;
@@ -72,7 +72,7 @@ public APIResponseDTO handler(Exception e) {
7272
String errorStr = MessageFormat.format("unknown error: {0}" ,e.getMessage());
7373
logger.error(errorStr, e);
7474
}
75-
String rstr = "[response] " + response.getResponse().toJSONString();
75+
String rstr = "[response] " + response.getResponse().toString();
7676
logger.info(rstr);
7777
String endHandle = "[thread-" + Thread.currentThread().getId() + "] End to handle request.";
7878
logger.info(endHandle);

g11n-ws/modules/md-restful-api-i18n/src/main/java/com/vmware/vip/i18n/api/base/StreamProductAction.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 VMware, Inc.
2+
* Copyright 2019-2025 VMware, Inc.
33
* SPDX-License-Identifier: EPL-2.0
44
*/
55
package com.vmware.vip.i18n.api.base;
@@ -14,8 +14,8 @@
1414
import com.vmware.vip.core.messages.service.product.IProductService;
1515
import com.vmware.vip.messages.data.dao.model.ResultMessageChannel;
1616
import org.apache.commons.lang3.StringUtils;
17-
import org.json.simple.JSONArray;
18-
import org.json.simple.JSONObject;
17+
import org.json.JSONArray;
18+
import org.json.JSONObject;
1919
import org.springframework.beans.factory.annotation.Autowired;
2020

2121
import jakarta.servlet.http.HttpServletResponse;
@@ -193,13 +193,13 @@ private void writePseudoTranslationsToChannel(String productName, String version
193193
resp.setContentType(ConstantsKeys.CONTENT_TYPE_JSON);
194194
WritableByteChannel wbc = Channels.newChannel(resp.getOutputStream());
195195

196-
boolean isPartContent = writeResponseHeader(reqVersion.equals(versionStr), components.size() * locales.size(), result.size(), wbc, sr);
196+
boolean isPartContent = writeResponseHeader(reqVersion.equals(versionStr), components.size() * locales.size(), result.toList().size(), wbc, sr);
197197
List<JSONObject> resultList = formatResultBundles(components, locales, result, isPartContent);
198-
wbc.write(ByteBuffer.wrap(resultList.get(0).toJSONString().getBytes()));
198+
wbc.write(ByteBuffer.wrap(resultList.get(0).toString().getBytes()));
199199
ByteBuffer buf = ByteBuffer.wrap(byteComm);
200200
for (int i =1; i<resultList.size(); i++){
201201
wbc.write(buf);
202-
wbc.write(ByteBuffer.wrap(resultList.get(0).toJSONString().getBytes()));
202+
wbc.write(ByteBuffer.wrap(resultList.get(0).toString().getBytes()));
203203
((Buffer) buf).rewind();
204204
}
205205
wbc.write(sr.getEndBytes());
@@ -214,18 +214,18 @@ private List<JSONObject> formatResultBundles(List<String> components, List<Strin
214214
}
215215
}
216216
}else {
217-
Iterator<JSONObject> objectIterator = result.iterator();
217+
Iterator<Object> objectIterator = result.iterator();
218218
while(objectIterator.hasNext()) {
219-
resultList.add(objectIterator.next());
219+
resultList.add((JSONObject) objectIterator.next());
220220
}
221221
}
222222
return resultList;
223223
}
224224
private JSONObject addNullBundle(String component, String locale, JSONArray result){
225225

226-
Iterator<JSONObject> objectIterator = result.iterator();
226+
Iterator<Object> objectIterator = result.iterator();
227227
while(objectIterator.hasNext()) {
228-
JSONObject object = objectIterator.next();
228+
JSONObject object = (JSONObject) objectIterator.next();
229229
String fileLocale = (String) object.get(ConstantsKeys.lOCALE);
230230
String fileComponent = (String) object.get(ConstantsKeys.COMPONENT);
231231
if(locale.equals(fileLocale)&& component.equals(fileComponent)) {
@@ -235,7 +235,7 @@ private JSONObject addNullBundle(String component, String locale, JSONArray resu
235235
JSONObject nullObj = new JSONObject();
236236
nullObj.put("locale", locale);
237237
nullObj.put("component", component);
238-
nullObj.put("messages", null);
238+
// nullObj.put("messages", null);
239239
return nullObj;
240240
}
241241

g11n-ws/modules/md-restful-api-i18n/src/main/java/com/vmware/vip/i18n/api/base/TranslationProductAction.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 VMware, Inc.
2+
* Copyright 2019-2025 VMware, Inc.
33
* SPDX-License-Identifier: EPL-2.0
44
*/
55
package com.vmware.vip.i18n.api.base;
@@ -16,8 +16,8 @@
1616
import jakarta.servlet.http.HttpServletRequest;
1717
import jakarta.servlet.http.HttpServletResponse;
1818
import org.apache.commons.lang3.StringUtils;
19-
import org.json.simple.JSONArray;
20-
import org.json.simple.JSONObject;
19+
import org.json.JSONArray;
20+
import org.json.JSONObject;
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
2323
import org.springframework.beans.factory.annotation.Autowired;
@@ -153,7 +153,7 @@ private JSONObject getNUllBundle(String component, String locale) {
153153
JSONObject object = new JSONObject();
154154
object.put("locale", locale);
155155
object.put("component", component);
156-
object.put("messages", null);
156+
// object.put("messages", null);
157157
return object;
158158

159159
}
@@ -163,10 +163,10 @@ private JSONObject getBundle(String component, String locale, TranslationDTO all
163163

164164
JSONArray array = allTranslationDTO.getBundles();
165165
@SuppressWarnings("unchecked")
166-
Iterator<JSONObject> objectIterator = array.iterator();
166+
Iterator<Object> objectIterator = array.iterator();
167167

168168
while (objectIterator.hasNext()) {
169-
JSONObject object = objectIterator.next();
169+
JSONObject object = (JSONObject) objectIterator.next();
170170
String fileLocale = (String) object.get(ConstantsKeys.lOCALE);
171171
String fileComponent = (String) object.get(ConstantsKeys.COMPONENT);
172172
if (locale.equals(fileLocale) && component.equals(fileComponent)) {
@@ -203,7 +203,7 @@ public APIResponseDTO getPartialComTrans(String productName,
203203
for (String locale : reqLocales) {
204204
JSONObject jsonObj = getBundle(component, locale, allTranslationDTO);
205205
if (jsonObj != null) {
206-
ja.add(jsonObj);
206+
ja.put(jsonObj);
207207
} else {
208208
jsonNullList.add(getNUllBundle(component, locale));
209209
}
@@ -215,12 +215,12 @@ public APIResponseDTO getPartialComTrans(String productName,
215215

216216
if (ja.isEmpty()) {
217217
throw new L3APIException(ConstantsMsg.TRANS_IS_NOT_FOUND);
218-
} else if (ja.size() == (reqLocaleSize * reqComponentSite)) {
218+
} else if (ja.toList().size() == (reqLocaleSize * reqComponentSite)) {
219219
resulttranslationDTO.setBundles(ja);
220220
return super.handleVersionFallbackResponse(oldVersion, version, resulttranslationDTO);
221221
} else {
222222
for (JSONObject jsonNullObj : jsonNullList) {
223-
ja.add(jsonNullObj);
223+
ja.put(jsonNullObj);
224224
}
225225
resulttranslationDTO.setBundles(ja);
226226
if (oldVersion.equals(version)) {

g11n-ws/modules/md-restful-api-i18n/src/main/java/com/vmware/vip/i18n/api/base/TranslationProductComponentAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 VMware, Inc.
2+
* Copyright 2019-2025 VMware, Inc.
33
* SPDX-License-Identifier: EPL-2.0
44
*/
55
package com.vmware.vip.i18n.api.base;
@@ -14,7 +14,7 @@
1414

1515

1616
import org.apache.commons.lang3.StringUtils;
17-
import org.json.simple.JSONObject;
17+
import org.json.JSONObject;
1818
import org.springframework.beans.factory.annotation.Autowired;
1919

2020
import com.vmware.vip.common.constants.ConstantsKeys;
@@ -138,7 +138,7 @@ public APIResponseDTO checkTranslationResult(String productName, String componen
138138
}
139139
}
140140

141-
((ComponentMessagesDTO)o).setStatus(JSONObject.toJSONString(r));
141+
((ComponentMessagesDTO)o).setStatus(new JSONObject(r).toString());
142142
}
143143
if(!r.isEmpty() && !r.containsValue("0")) {
144144
return super.handleResponse(APIResponseStatus.TRANSLATION_READY, resp.getData());

g11n-ws/modules/md-restful-api-i18n/src/main/java/com/vmware/vip/i18n/api/v1/translation/TranslationComponentAPI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 VMware, Inc.
2+
* Copyright 2019-2025 VMware, Inc.
33
* SPDX-License-Identifier: EPL-2.0
44
*/
55
package com.vmware.vip.i18n.api.v1.translation;
@@ -121,7 +121,7 @@ public APIResponseDTO getMultipleComponentsTranslation(
121121
translationDTO.setLocales(localeList);
122122
translationDTO.setPseudo(Boolean.parseBoolean(pseudo));
123123
translationDTO =multipleComponentsService.getMultiComponentsTranslation(translationDTO);
124-
if(translationDTO.getBundles() == null || translationDTO.getBundles().size() == 0) {
124+
if(translationDTO.getBundles() == null || translationDTO.getBundles().toList().size() == 0) {
125125
throw new L3APIException(String.format(ConstantsMsg.TRANS_GET_FAILD, productName + ConstantsChar.BACKSLASH + version));
126126
}
127127
return super.handleResponse(APIResponseStatus.OK, translationDTO);

g11n-ws/modules/md-restful-api-i18n/src/main/java/com/vmware/vip/i18n/api/v1/translation/TranslationProductComponentAPI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 VMware, Inc.
2+
* Copyright 2019-2025 VMware, Inc.
33
* SPDX-License-Identifier: EPL-2.0
44
*/
55
package com.vmware.vip.i18n.api.v1.translation;
@@ -68,7 +68,7 @@ public APIResponseDTO getMultipleComponentsTrans(
6868
HttpServletRequest req) throws Exception {
6969
APIResponseDTO resp = super.getMultipleComponentsTrans(productName, components, version, locales, pseudo, req);
7070
TranslationDTO translationDTO = (TranslationDTO) resp.getData();
71-
if (translationDTO.getBundles() == null || translationDTO.getBundles().size() == 0) {
71+
if (translationDTO.getBundles() == null || translationDTO.getBundles().toList().size() == 0) {
7272
throw new L3APIException(
7373
String.format(ConstantsMsg.TRANS_GET_FAILD, productName + ConstantsChar.BACKSLASH + version));
7474
}

g11n-ws/modules/md-restful-synch/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies {
1818
api project(":md-service-i18n-l3")
1919
compileOnly("org.apache.httpcomponents:httpclient:$httpclient")
2020
api("com.alibaba:fastjson:1.2.51")
21-
implementation("com.googlecode.json-simple:json-simple:$jsonSimpleVersion"){
21+
implementation("org.json:json:$jsonVersion"){
2222
exclude group: 'junit'
2323
}
2424
compileOnly("org.springdoc:springdoc-openapi-starter-webmvc-api:$springdocVersion")

g11n-ws/modules/md-restful-synch/src/main/java/com/vmware/vip/messages/synch/service/SynchServiceImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 VMware, Inc.
2+
* Copyright 2019-2025 VMware, Inc.
33
* SPDX-License-Identifier: EPL-2.0
44
*/
55
package com.vmware.vip.messages.synch.service;
@@ -11,7 +11,7 @@
1111
import java.util.Map;
1212

1313
import com.vmware.vip.common.cache.SingletonCache;
14-
import org.json.simple.parser.ParseException;
14+
import org.json.JSONException;
1515
import org.slf4j.Logger;
1616
import org.slf4j.LoggerFactory;
1717
import org.springframework.beans.factory.annotation.Autowired;
@@ -49,7 +49,7 @@ public List<String> updateTranslationBatch(List<ComponentMessagesDTO> comps) {
4949
// TODO Auto-generated catch block
5050
logger.error(e.getMessage(), e);
5151
fileResult = null;
52-
} catch (ParseException e) {
52+
} catch (JSONException e) {
5353
// TODO Auto-generated catch block
5454
logger.error(e.getMessage(), e);
5555
fileResult = null;
@@ -77,7 +77,7 @@ public List<String> updateTranslationBatch(List<ComponentMessagesDTO> comps) {
7777

7878

7979
public File updateTranslation(ComponentMessagesDTO componentMessagesDTO)
80-
throws DataException, ParseException, VIPCacheException {
80+
throws DataException, JSONException, VIPCacheException {
8181
String key = CachedKeyGetter.getOneCompnentCachedKey(componentMessagesDTO);
8282
File updateFile;
8383
ComponentMessagesDTO result = singletonCache.getCachedObject(CacheName.ONECOMPONENT, key, ComponentMessagesDTO.class);

0 commit comments

Comments
 (0)