pax_global_header 0000666 0000000 0000000 00000000064 14753022552 0014517 g ustar 00root root 0000000 0000000 52 comment=d4f7fa4f31e20145d20393c5e79c6255954cb81e
netplex-json-smart-v2-20dff24/ 0000775 0000000 0000000 00000000000 14753022552 0016227 5 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/.github/ 0000775 0000000 0000000 00000000000 14753022552 0017567 5 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/.github/FUNDING.yml 0000664 0000000 0000000 00000000020 14753022552 0021374 0 ustar 00root root 0000000 0000000 github: urielch
netplex-json-smart-v2-20dff24/.github/dependabot.yml 0000664 0000000 0000000 00000000341 14753022552 0022415 0 ustar 00root root 0000000 0000000 version: 2
updates:
- package-ecosystem: "maven"
directory: "json-smart"
schedule:
interval: "monthly"
- package-ecosystem: "maven"
directory: "json-smart-action"
schedule:
interval: "monthly"
netplex-json-smart-v2-20dff24/.github/workflows/ 0000775 0000000 0000000 00000000000 14753022552 0021624 5 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/.github/workflows/json-smart-unit-tests.yml 0000664 0000000 0000000 00000001514 14753022552 0026562 0 ustar 00root root 0000000 0000000
name: json smart unit tests
on:
push:
branches:
- master
- update2024
pull_request:
branches:
- master
jobs:
publish:
runs-on: ubuntu-latest
strategy:
matrix:
java-version: [8, 11, 16, 17, 21]
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
cache: 'maven'
- name: Unit tests accessors-smart
run: cd accessors-smart; mvn -B install; mvn -B clean test
- name: Unit tests json-smart
run: cd json-smart; mvn -B install; mvn -B clean test
- name: Unit tests json-smart-action
run: cd json-smart-action; mvn -B install; mvn -B clean test
netplex-json-smart-v2-20dff24/.gitignore 0000664 0000000 0000000 00000000161 14753022552 0020215 0 ustar 00root root 0000000 0000000 # file system
.DS_Store
**/.classpath
**/.idea/
**/.project
**/.settings/
**/*.iml
**/bin
**/target
**/.vscode/
netplex-json-smart-v2-20dff24/.vscode/ 0000775 0000000 0000000 00000000000 14753022552 0017570 5 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/.vscode/settings.json 0000664 0000000 0000000 00000000102 14753022552 0022314 0 ustar 00root root 0000000 0000000 {
"java.configuration.updateBuildConfiguration": "automatic"
} netplex-json-smart-v2-20dff24/LICENSE 0000664 0000000 0000000 00000026136 14753022552 0017244 0 ustar 00root root 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
netplex-json-smart-v2-20dff24/README.md 0000664 0000000 0000000 00000014221 14753022552 0017506 0 ustar 00root root 0000000 0000000 # json-smart-v2
[](https://travis-ci.org/netplex/json-smart-v2)
[](https://maven-badges.herokuapp.com/maven-central/net.minidev/json-smart/)
[](https://coveralls.io/github/netplex/json-smart-v2?branch=master)
Json-smart development started in 2010, when SQL servers did not support native JSON fields, NoSQL databases were slowly emerging, and all the existing JSON APIs were bogus. I wrote lots of tests to benchmark and compare JSON java parsers.
I never liked SQL databases because it's almost impossible to update a data model without impacting the production platform. Adding a column is a terrible operation.
So I started json-smart. All non-indexed data in my datastores were stored in a column as a serialized JSON message. To fit MySQL varchar(255) fields, I tried to make my JSON as small as possible, so json-smart is optimized to produce small JSON-like Strings.
Now times have changed: most of the JSON APIs are now stable, and I'm now using document-oriented databases and JSON-native SQL types.
So I do not use my json-smart anymore. I had fun with this project. If you want to apply some change on json-smart create a pull request with lots of JUnit tests.
[WIKI is here](https://github.com/netplex/json-smart/wiki)
# Changelog
### *V 2.5.2* (next version)
* Fix CVE-2024-57699 for predefined parsers. [PR 233](https://github.com/netplex/json-smart-v2/pull/233)
### *V 2.5.1* (2024-03-14)
* Bump all dependencies.
* Fix OSGi import package version for net.minidev.asm. [PR 180](https://github.com/netplex/json-smart-v2/pull/180)
### *V 2.5.0* (2023-07-10)
* Add flag to drop the limit of json depth. [PR 156](https://github.com/netplex/json-smart-v2/pull/156)
### *V 2.4.11* (2023-05-18)
* Fix error in isWritable in accessor-smart. [PR 147](https://github.com/netplex/json-smart-v2/pull/147)
* Update json-smart dependency to use accessor-smart:2.4.11
### *V 2.4.10* (2023-03-17)
* Fix unstacking issue with more than 400 elements in an array.
### *V 2.4.9* (2023-03-07)
* Add depth limit of 400 when parsing JSON.
### *V 2.4.8* (2022-02-13)
* Fix the incorrect double compare with e,E+,e+ [PR 77](https://github.com/netplex/json-smart-v2/pull/77)
### *V 2.4.7* (2021-06-02)
* full timezone support in date parsing
* set default charset to UTF-8 when parsing byte[] contents
* overwride system default encoding when parssing bytes[] [PR 71](https://github.com/netplex/json-smart-v2/pull/74)
### *V 2.4.6* (2021-04-23)
* Correct publish issue 3th time [issue 69](https://github.com/netplex/json-smart-v2/issues/69)
* Support latest asm in accessor-smart [issue 70](https://github.com/netplex/json-smart-v2/issues/70)
* Drop legacy parent pom
### *V 2.4.5* (2021-04-19)
* Correct publish issue 2nd time [issue 69](https://github.com/netplex/json-smart-v2/issues/69)
### *V 2.4.4* (2021-04-17)
* Correct publish issue 1st time [issue 69](https://github.com/netplex/json-smart-v2/issues/69)
* fix ArrayIndexOutOfBoundsException [issue 68](https://github.com/netplex/json-smart-v2/pull/68)
### *V 2.4.2* (2021-04-04)
### *V 2.4.2* (2021-04-03)
* add BIG_DIGIT_UNRESTRICTED to avoid BigDigit usage on some Double.
* fix CVE-2021-27568
* java 11 build
### *V 2.3.1* (2021-05-02)
* Fixes [issue #60](https://github.com/netplex/json-smart-v2/issues/60) (CVE-2021-27568)
* full timezone support in date parsing
### *V 2.3* (2017-03-26)
* Patch 37 [issue 37](http://code.google.com/p/json-smart/issues/detail?id=37)
* Explicite support of char 127 [issue 18](http://code.google.com/p/json-smart/issues/detail?id=18)
* Integrate json-smart-action from Eitan Raviv [PR 31](https://github.com/netplex/json-smart-v2/pull/31)
* Remove hard codded e.printStackTrace() [issue 33](https://github.com/netplex/json-smart-v2/issues/33)
* Improve date parsing code to support all timeZones [issue 29](https://github.com/netplex/json-smart-v2/issues/29)
### *V 2.2.2*
* Fix support for default java datetime format for US locale
* Update my time Zone from Paris to San Francisco.
### *V 2.2.1* (2015-10-08)
* Fix issue in strict mode [issue gh-17](https://github.com/netplex/json-smart-v2/issues/17)
* Add a licence Copy at the root project level [issue gh-16](https://github.com/netplex/json-smart-v2/issues/16)
* Change InputStream input reading to use UTF8. [issue 48](http://code.google.com/p/json-smart/issues/detail?id=48)
### *V 2.2* (2015-07-29)
* Rename asm to accessors-smart due to conflict name with asm.ow2.org lib. fix [PR-10](https://github.com/netplex/json-smart-v2/pull/10)
* Fix OSGI error fix [PR-2](https://github.com/netplex/json-smart-v2/pull/2)
* Add support for BigDecimal
* Improve JSONObject.getAsNumber() helper
* Add a Field Remaper
### *V 2.1.0* (2014-10-19)
* net.minidev.json.mapper renamed to net.minidev.json.writer
* Add ACCEPT_TAILLING_SPACE Parssing Flag.
* Mapper classes now non static.
* Reader mapper are now available in net.minidev.json.reader.JsonReader class
* Writer mapper are now available in net.minidev.json.writer.JsonWriter class
### *V 2.0* (2014-08-12)
* Fix Double Identification [issue 44](http://code.google.com/p/json-smart/issues/detail?id=44)
* Fix Collection Interface Serialisation
* Fix security Exception in ASM code
* Project moved to GitHub
* Fix [issue 42](http://code.google.com/p/json-smart/issues/detail?id=42)
### *V 2.0-RC3* (2013-08-14)
* Add custom data binding inside the ASM layer.
* Add Date support
* Add \x escape sequence support [issue 39](http://code.google.com/p/json-smart/issues/detail?id=39)
* fix issue [issue 37](http://code.google.com/p/json-smart/issues/detail?id=37)
### *V 2.0-RC2* (2012-04-03)
* Fix critical [issue 23](http://code.google.com/p/json-smart/issues/detail?id=23)
* Improve Javadoc in JSONStyle [issue 24](http://code.google.com/p/json-smart/issues/detail?id=23)
### *V 2.0-RC1* (2012-02-18)
* speed improvement in POJO manipulation
* add JSONStyle.LT_COMPRESS predefined generate strct json, but ignoring / escapement. netplex-json-smart-v2-20dff24/accessors-smart/ 0000775 0000000 0000000 00000000000 14753022552 0021340 5 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/accessors-smart/.gitignore 0000664 0000000 0000000 00000000011 14753022552 0023320 0 ustar 00root root 0000000 0000000 /target/
netplex-json-smart-v2-20dff24/accessors-smart/pom.xml 0000664 0000000 0000000 00000027123 14753022552 0022662 0 ustar 00root root 0000000 0000000
4.0.0net.minidevaccessors-smart2.5.2ASM based accessors helper used by json-smartJava reflect give poor performance on getter setter an constructor calls, accessors-smart use ASM to speed up those calls.bundlehttps://urielch.github.io/Chemouni Urielhttps://urielch.github.io/urielUriel Chemouniuchemouni@gmail.comGMT+1hezhangjianZhangjian Hehezhangjian97gmail.comGMT+8The Apache Software License, Version 2.0http://www.apache.org/licenses/LICENSE-2.0.txtrepoAll files under Apache 2UTF-8101.81.8scm:git:https://github.com/netplex/json-smart-v2.gitscm:git:https://github.com/netplex/json-smart-v2.githttps://github.com/netplex/json-smart-v2ossrhhttps://s01.oss.sonatype.org/content/repositories/snapshotsossrhhttps://s01.oss.sonatype.org/service/local/staging/deploy/maven2/release-sign-artifactsperformReleasetrue53BE126Dorg.apache.maven.pluginsmaven-gpg-plugin3.2.7sign-artifactsverifysignorg.apache.maven.pluginsmaven-javadoc-plugin3.10.18attach-javadocsjarorg.apache.maven.pluginsmaven-release-plugin3.1.1forked-path-Psonatype-oss-releasefalsefalsereleasedeployinclude-sources/truesrc/main/java**/*.javaorg.apache.maven.pluginsmaven-source-plugin3.3.1bind-sourcesjar-no-forkorg.apache.maven.pluginsmaven-compiler-plugin3.13.0UTF-8${maven.compiler.source}${maven.compiler.target}org.apache.maven.pluginsmaven-resources-plugin3.3.1UTF-8org.apache.maven.pluginsmaven-jar-plugin3.4.2org.apache.maven.pluginsmaven-javadoc-plugin3.10.18falseattach-javadocsjarorg.apache.felixmaven-bundle-plugin5.1.9true${project.groupId}.${project.artifactId}${project.artifactId}${project.version}
org.objectweb.asm;version="[8.0,10)",*
net.minidev.asm, net.minidev.asm.ex
org.junit.jupiterjunit-jupiter-api5.11.2testorg.ow2.asmasm9.7.1
netplex-json-smart-v2-20dff24/accessors-smart/src/ 0000775 0000000 0000000 00000000000 14753022552 0022127 5 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/accessors-smart/src/main/ 0000775 0000000 0000000 00000000000 14753022552 0023053 5 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/accessors-smart/src/main/java/ 0000775 0000000 0000000 00000000000 14753022552 0023774 5 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/accessors-smart/src/main/java/net/ 0000775 0000000 0000000 00000000000 14753022552 0024562 5 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/accessors-smart/src/main/java/net/minidev/ 0000775 0000000 0000000 00000000000 14753022552 0026215 5 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/accessors-smart/src/main/java/net/minidev/asm/ 0000775 0000000 0000000 00000000000 14753022552 0026775 5 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/accessors-smart/src/main/java/net/minidev/asm/ASMUtil.java 0000664 0000000 0000000 00000021157 14753022552 0031124 0 ustar 00root root 0000000 0000000 package net.minidev.asm;
/*
* Copyright 2011-2024 JSON-SMART authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static org.objectweb.asm.Opcodes.CHECKCAST;
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
import java.lang.reflect.Field;
import java.util.HashMap;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
/**
* ASM Utils used to simplify class generation
*
* @author uriel Chemouni
*/
public class ASMUtil {
/**
* default constructor
*/
public ASMUtil() {
super();
}
/**
* Append the call of proper autoboxing method for the given primitive type.
*
* @param mv MethodVisitor
* @param clz expected class
*/
public static void autoBoxing(MethodVisitor mv, Class> clz) {
autoBoxing(mv, Type.getType(clz));
}
/**
* Extract all Accessor for the field of the given class.
*
* @param type type
* @param filter FieldFilter
* @return all Accessor available
*/
static public Accessor[] getAccessors(Class> type, FieldFilter filter) {
Class> nextClass = type;
HashMap map = new HashMap();
if (filter == null)
filter = BasicFiledFilter.SINGLETON;
while (nextClass != Object.class) {
Field[] declaredFields = nextClass.getDeclaredFields();
for (Field field : declaredFields) {
String fn = field.getName();
if (map.containsKey(fn))
continue;
Accessor acc = new Accessor(nextClass, field, filter);
if (!acc.isUsable())
continue;
map.put(fn, acc);
}
nextClass = nextClass.getSuperclass();
}
return map.values().toArray(new Accessor[map.size()]);
}
/**
* Append the call of proper autoboxing method for the given primitive type.
*
* @param mv MethodVisitor
* @param fieldType expected class
*/
protected static void autoBoxing(MethodVisitor mv, Type fieldType) {
switch (fieldType.getSort()) {
case Type.BOOLEAN:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false);
break;
case Type.BYTE:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false);
break;
case Type.CHAR:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;", false);
break;
case Type.SHORT:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false);
break;
case Type.INT:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
break;
case Type.FLOAT:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false);
break;
case Type.LONG:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
break;
case Type.DOUBLE:
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false);
break;
}
}
/**
* Append the call of proper extract primitive type of an boxed object.
*
* @param mv MethodVisitor
* @param fieldType expected class
*/
protected static void autoUnBoxing1(MethodVisitor mv, Type fieldType) {
switch (fieldType.getSort()) {
case Type.BOOLEAN:
mv.visitTypeInsn(CHECKCAST, "java/lang/Boolean");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
break;
case Type.BYTE:
mv.visitTypeInsn(CHECKCAST, "java/lang/Byte");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "()B", false);
break;
case Type.CHAR:
mv.visitTypeInsn(CHECKCAST, "java/lang/Character");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Character", "charValue", "()C", false);
break;
case Type.SHORT:
mv.visitTypeInsn(CHECKCAST, "java/lang/Short");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Short", "shortValue", "()S", false);
break;
case Type.INT:
mv.visitTypeInsn(CHECKCAST, "java/lang/Integer");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
break;
case Type.FLOAT:
mv.visitTypeInsn(CHECKCAST, "java/lang/Float");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F", false);
break;
case Type.LONG:
mv.visitTypeInsn(CHECKCAST, "java/lang/Long");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
break;
case Type.DOUBLE:
mv.visitTypeInsn(CHECKCAST, "java/lang/Double");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false);
break;
case Type.ARRAY:
mv.visitTypeInsn(CHECKCAST, fieldType.getInternalName());
break;
default:
mv.visitTypeInsn(CHECKCAST, fieldType.getInternalName());
}
}
/**
* Append the call of proper extract primitive type of an boxed object. this
* method use Number interface to unbox object
*
* @param mv MethodVisitor
* @param fieldType expected class
*/
protected static void autoUnBoxing2(MethodVisitor mv, Type fieldType) {
switch (fieldType.getSort()) {
case Type.BOOLEAN:
mv.visitTypeInsn(CHECKCAST, "java/lang/Boolean");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
break;
case Type.BYTE:
mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "byteValue", "()B", false);
break;
case Type.CHAR:
mv.visitTypeInsn(CHECKCAST, "java/lang/Character");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Character", "charValue", "()C", false);
break;
case Type.SHORT:
mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "shortValue", "()S", false);
break;
case Type.INT:
mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "intValue", "()I", false);
break;
case Type.FLOAT:
mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "floatValue", "()F", false);
break;
case Type.LONG:
mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "longValue", "()J", false);
break;
case Type.DOUBLE:
mv.visitTypeInsn(CHECKCAST, "java/lang/Number");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Number", "doubleValue", "()D", false);
break;
case Type.ARRAY:
mv.visitTypeInsn(CHECKCAST, fieldType.getInternalName());
break;
default:
mv.visitTypeInsn(CHECKCAST, fieldType.getInternalName());
}
}
/**
* return a array of new Label (used for switch/case generation)
*
* @param cnt number of label to return
* @return a Label array
*/
public static Label[] newLabels(int cnt) {
Label[] r = new Label[cnt];
for (int i = 0; i < cnt; i++)
r[i] = new Label();
return r;
}
/**
* Generates a setter method name for a given field name.
*
* @param key the field name
* @return setter name
*/
public static String getSetterName(String key) {
int len = key.length();
char[] b = new char[len + 3];
b[0] = 's';
b[1] = 'e';
b[2] = 't';
char c = key.charAt(0);
if (c >= 'a' && c <= 'z')
c += 'A' - 'a';
b[3] = c;
for (int i = 1; i < len; i++) {
b[i + 3] = key.charAt(i);
}
return new String(b);
}
/**
* Generates a getter method name for a given field name.
*
* @param key the field name
* @return getter name
*/
public static String getGetterName(String key) {
int len = key.length();
char[] b = new char[len + 3];
b[0] = 'g';
b[1] = 'e';
b[2] = 't';
char c = key.charAt(0);
if (c >= 'a' && c <= 'z')
c += 'A' - 'a';
b[3] = c;
for (int i = 1; i < len; i++) {
b[i + 3] = key.charAt(i);
}
return new String(b);
}
/**
* Generates a boolean getter method name (is-method) for a given field name.
*
* @param key the boolean field name
* @return boolean getter name
*/
public static String getIsName(String key) {
int len = key.length();
char[] b = new char[len + 2];
b[0] = 'i';
b[1] = 's';
char c = key.charAt(0);
if (c >= 'a' && c <= 'z')
c += 'A' - 'a';
b[2] = c;
for (int i = 1; i < len; i++) {
b[i + 2] = key.charAt(i);
}
return new String(b);
}
}
netplex-json-smart-v2-20dff24/accessors-smart/src/main/java/net/minidev/asm/Accessor.java 0000664 0000000 0000000 00000010244 14753022552 0031403 0 ustar 00root root 0000000 0000000 package net.minidev.asm;
/*
* Copyright 2011-2024 JSON-SMART authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
/**
* Contains all information needed to access a java field.
*
* field, getter setter
*
* this object is used internally by BeansAccess
*
* @see BeansAccess
*
* @author Uriel Chemouni
*/
public class Accessor {
/**
* Field to access
*/
protected Field field;
/**
* Setter Methods if available
*/
protected Method setter;
/**
* getter Methods if available
*/
protected Method getter;
/**
* Filed index in object
*/
protected int index;
/**
* Filed Class
*/
protected Class> type;
/**
* Filed Type using JDK 5+ generics if available
*/
protected Type genericType;
/**
* The name of the field.
*/
protected String fieldName;
/**
* getter for index
* @return Index
*/
public int getIndex() {
return index;
}
/**
* is the field access using Field access type
* @return if Accessor is public
*/
public boolean isPublic() {
return setter == null && getter == null;
}
/**
* is the field is an enum field
* @return if Accessor return an Enum Class
*/
public boolean isEnum() {
return type.isEnum();
}
/**
* return the field name
* @return the field name
*/
public String getName() {
return fieldName;
}
/**
* return field Class
* @return field Class
*/
public Class> getType() {
return type;
}
/**
* return generics field Type.
* @return generics field Type.
*/
public Type getGenericType() {
return genericType;
}
/**
* Determines if the field is accessible for reading or writing operations.
*
* @return true if the field can be read or write
*/
public boolean isUsable() {
return field != null || getter != null || setter != null;
}
/**
* Checks if the field is readable, either directly or through a getter method.
*
* @return true if the field can be read
*/
public boolean isReadable() {
return field != null || getter != null;
}
/**
* Determines if the field is writable, either directly or through a setter method.
*
* @return true if the field can be write
*/
public boolean isWritable() {
return field != null || setter != null;
}
/**
* build accessor for a field
*
* @param c the handled class
* @param field the field to access
* @param filter field filter
*/
public Accessor(Class> c, Field field, FieldFilter filter) {
this.fieldName = field.getName();
int m = field.getModifiers();
if ((m & (Modifier.STATIC | Modifier.TRANSIENT)) > 0)
return;
if ((m & Modifier.PUBLIC) > 0)
this.field = field;
String name = ASMUtil.getSetterName(field.getName());
try {
setter = c.getDeclaredMethod(name, field.getType());
} catch (Exception e) {
}
boolean isBool = field.getType().equals(Boolean.TYPE);
if (isBool) {
name = ASMUtil.getIsName(field.getName());
} else {
name = ASMUtil.getGetterName(field.getName());
}
try {
getter = c.getDeclaredMethod(name);
} catch (Exception e) {
}
if (getter == null && isBool) {
try {
getter = c.getDeclaredMethod(ASMUtil.getGetterName(field.getName()));
} catch (Exception e) {
}
}
if (this.field == null && getter == null && setter == null)
return;
if (getter != null && !filter.canUse(field, getter))
getter = null;
if (setter != null && !filter.canUse(field, setter))
setter = null;
// no access disable
if (getter == null && setter == null && this.field == null)
return;
this.type = field.getType();
this.genericType = field.getGenericType();
}
}
netplex-json-smart-v2-20dff24/accessors-smart/src/main/java/net/minidev/asm/BasicFiledFilter.java 0000664 0000000 0000000 00000003617 14753022552 0033002 0 ustar 00root root 0000000 0000000 package net.minidev.asm;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* A basic implementation of the {@link FieldFilter} interface that permits all operations on fields.
* This implementation returns {@code true} for all checks, indicating that any field can be used, read, and written.
* It serves as a default or fallback strategy when no specific field filtering logic is required.
*/
public class BasicFiledFilter implements FieldFilter {
/**
* default constructor
*/
public BasicFiledFilter() {
super();
}
/**
* A singleton instance of {@code BasicFieldFilter}.
* Since the filter does not maintain any state and allows all operations, it can be reused across the application.
*/
public final static BasicFiledFilter SINGLETON = new BasicFiledFilter();
/**
* Always allows using the specified field.
*
* @param field The field to check.
* @return Always returns {@code true}.
*/
@Override
public boolean canUse(Field field) {
return true;
}
/**
* Always allows using the specified field in conjunction with a method.
*
* @param field The field to check.
* @param method The method to check. This parameter is not used in the current implementation.
* @return Always returns {@code true}.
*/
@Override
public boolean canUse(Field field, Method method) {
return true;
}
/**
* Always allows reading the specified field.
*
* @param field The field to check.
* @return Always returns {@code true}.
*/
@Override
public boolean canRead(Field field) {
return true;
}
/**
* Always allows writing to the specified field.
*
* @param field The field to check.
* @return Always returns {@code true}.
*/
@Override
public boolean canWrite(Field field) {
return true;
}
}
netplex-json-smart-v2-20dff24/accessors-smart/src/main/java/net/minidev/asm/BeansAccess.java 0000664 0000000 0000000 00000014272 14753022552 0032020 0 ustar 00root root 0000000 0000000 package net.minidev.asm;
/*
* Copyright 2011-2024 JSON-SMART authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
/**
* Allow access reflect field using runtime generated accessor. BeansAccessor is
* faster than java.lang.reflect.Method.invoke()
*
* @param the type of the bean being accessed
* @author uriel Chemouni
*/
public abstract class BeansAccess {
/**
* default constuctor
*/
public BeansAccess() {
super();
}
private HashMap map;
private Accessor[] accs;
/**
* set Accessor
* @param accs Accessor list
*/
protected void setAccessor(Accessor[] accs) {
int i = 0;
this.accs = accs;
map = new HashMap();
for (Accessor acc : accs) {
acc.index = i++;
map.put(acc.getName(), acc);
}
}
/**
* get internal map
* @return a map
*/
public HashMap getMap() {
return map;
}
/**
* get internal accessor
* @return Accessor list
*/
public Accessor[] getAccessors() {
return accs;
}
/**
* cache used to store built BeansAccess
*/
private static ConcurrentHashMap, BeansAccess>> cache = new ConcurrentHashMap, BeansAccess>>();
// private final static ConcurrentHashMap> cache;
/**
* return the BeansAccess corresponding to a type
*
* @param type to be access
* @param
working type
* @return the BeansAccess
*/
static public
BeansAccess
get(Class
type) {
return get(type, null);
}
/**
* return the BeansAccess corresponding to a type
*
* @param filter FieldFilter
* @param type to be access
* @param
working type
* @return the BeansAccess
*/
static public
* The resulting object 'cleanObject' would be {k0:{k3:v3}, k1:{k4:v4}}
*
* See unit tests for more examples
*
* @author adoneitan@gmail.com
*
*/
public class ElementRemover {
private Map elementsToRemove;
public ElementRemover(Map elementsToRemove) {
this.elementsToRemove = elementsToRemove == null ? Collections. emptyMap() : elementsToRemove;
}
public ElementRemover(JSONObject elementsToRemove) {
this.elementsToRemove = elementsToRemove == null ? Collections. emptyMap() : elementsToRemove;
}
public JSONObject remove(JSONObject objectToClean) {
JSONTraverseAction strategy = new RemoveElementsJsonAction(this.elementsToRemove);
JSONTraverser traversal = new JSONTraverser(strategy);
traversal.traverse(objectToClean);
return (JSONObject) strategy.result();
}
}
PathLocator.java 0000664 0000000 0000000 00000004436 14753022552 0034100 0 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/json-smart-action/src/main/java/net/minidev/json/actions package net.minidev.json.actions;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.actions.path.DotDelimiter;
import net.minidev.json.actions.path.PathDelimiter;
import net.minidev.json.actions.traverse.JSONTraverser;
import net.minidev.json.actions.traverse.LocatePathsJsonAction;
import net.minidev.json.actions.traverse.JSONTraverseAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Searches for paths in a {@link JSONObject} and returns those found.
*
* Traverses the specified {@link JSONObject} searching for nodes whose paths (from the root down) match
* any of the user-specified paths. The paths that match are returned.
*
* A path to locate must be specified in the n-gram format - a list of keys from the root down separated by dots:
* K0[[[[.K1].K2].K3]...]
*
* A key to the right of a dot is a direct child of a key to the left of a dot. Keys with a dot in their name are
* not supported.
*
*
* @author adoneitan@gmail.com
*/
public class PathLocator {
protected List pathsToFind;
protected PathDelimiter pathDelimiter = new DotDelimiter().withAcceptDelimiterInNodeName(false);
public PathLocator(JSONArray pathsToFind) {
if (pathsToFind == null || pathsToFind.isEmpty()) {
this.pathsToFind = Collections.emptyList();
} else {
this.pathsToFind = new ArrayList();
for (Object s : pathsToFind) {
this.pathsToFind.add((String) s);
}
}
}
public PathLocator(List pathsToFind) {
this.pathsToFind = pathsToFind == null || pathsToFind.size() == 0 ? Collections. emptyList() : pathsToFind;
}
public PathLocator(String... pathsToFind) {
this.pathsToFind = pathsToFind == null || pathsToFind.length == 0 ? Collections. emptyList() : Arrays.asList(pathsToFind);
}
public PathLocator with(PathDelimiter pathDelimiter) {
this.pathDelimiter = pathDelimiter;
return this;
}
@SuppressWarnings("unchecked")
public List locate(JSONObject object) {
JSONTraverseAction action = new LocatePathsJsonAction(this.pathsToFind, pathDelimiter);
JSONTraverser traversal = new JSONTraverser(action).with(pathDelimiter);
traversal.traverse(object);
return (List) action.result();
}
}
PathRemover.java 0000664 0000000 0000000 00000004262 14753022552 0034111 0 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/json-smart-action/src/main/java/net/minidev/json/actions package net.minidev.json.actions;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.actions.traverse.JSONTraverser;
import net.minidev.json.actions.traverse.RemovePathsJsonAction;
import net.minidev.json.actions.traverse.JSONTraverseAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Removes branches of nodes from a {@link JSONObject} matching the list of user-specified paths.
*
* A path to remove must be specified in the n-gram format - a list of keys from the root down separated by dots:
* K0[[[[.K1].K2].K3]...]
*
* A key to the right of a dot is a direct child of a key to the left of a dot. Keys with a dot in their name are
* not supported.
*
* Usage Example:
*
* To remove the field k1.k2 from the {@link JSONObject} {k1:{k2:v2}, k3:{k4:v4}} use the remover like so:
*
* The resulting object 'cleanObject' would be {k1:{k3:{k4:v4}}}
*
* See unit tests for more examples
*
* @author adoneitan@gmail.com
*
*/
public class PathRemover {
protected List pathsToRemove;
public PathRemover(JSONArray pathsToRemove) {
if (pathsToRemove == null || pathsToRemove.isEmpty()) {
this.pathsToRemove = Collections.emptyList();
} else {
this.pathsToRemove = new ArrayList();
for (Object s : pathsToRemove) {
this.pathsToRemove.add((String) s);
}
}
}
public PathRemover(List pathsToRemove) {
this.pathsToRemove = pathsToRemove == null || pathsToRemove.size() == 0 ? Collections. emptyList() : pathsToRemove;
}
public PathRemover(String... pathsToRemove) {
this.pathsToRemove = pathsToRemove == null || pathsToRemove.length == 0 ? Collections. emptyList() : Arrays.asList(pathsToRemove);
}
public JSONObject remove(JSONObject objectToClean) {
JSONTraverseAction strategy = new RemovePathsJsonAction(this.pathsToRemove);
JSONTraverser traversal = new JSONTraverser(strategy);
traversal.traverse(objectToClean);
return (JSONObject) strategy.result();
}
}
PathReplicator.java 0000664 0000000 0000000 00000004451 14753022552 0034576 0 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/json-smart-action/src/main/java/net/minidev/json/actions package net.minidev.json.actions;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.actions.navigate.CopyPathsAction;
import net.minidev.json.actions.navigate.JSONNavigator;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Creates a copy of a {@link JSONObject} consisting only of the nodes on the user-specified paths.
*
* Paths that do not exist in the specified object are ignored silently. Specifying an empty list of paths
* to copy or only non-existent paths will result in an empty object being returned.
*
* A path to copy must be specified in the n-gram format - a list of keys from the root down separated by dots:
* K0[[[[.K1].K2].K3]...]
*
* A key to the right of a dot is a direct child of a key to the left of a dot. Keys with a dot in their name are
* not supported.
*
* Sample usage:
*
* To replicate the branch k1.k2 from {k1:{k2:v2}, k3:{k4:v4}} use the {@link PathReplicator} like so:
*
* The resulting object 'copiedObject' would be {k1:{k2:v2}}
*
* see unit tests for more examples
*
* @author adoneitan@gmail.com
* @since 15 March 2016.
*/
public class PathReplicator {
protected List pathsToCopy;
public PathReplicator(JSONArray pathsToCopy) {
if (pathsToCopy == null || pathsToCopy.isEmpty()) {
this.pathsToCopy = Collections.emptyList();
} else {
this.pathsToCopy = new LinkedList();
for (Object s : pathsToCopy) {
this.pathsToCopy.add((String) s);
}
}
}
public PathReplicator(List pathsToCopy) {
this.pathsToCopy = pathsToCopy == null || pathsToCopy.size() == 0 ? Collections. emptyList() : pathsToCopy;
}
public PathReplicator(String... pathsToCopy) {
this.pathsToCopy = pathsToCopy == null || pathsToCopy.length == 0 ? Collections. emptyList()
: new LinkedList(Arrays.asList(pathsToCopy));
}
public JSONObject replicate(JSONObject sourceObj) throws Exception {
CopyPathsAction s = new CopyPathsAction();
JSONNavigator n = new JSONNavigator(s, pathsToCopy);
n.nav(sourceObj);
return (JSONObject) s.result();
}
}
PathsRetainer.java 0000664 0000000 0000000 00000006317 14753022552 0034431 0 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/json-smart-action/src/main/java/net/minidev/json/actions package net.minidev.json.actions;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.actions.path.DotDelimiter;
import net.minidev.json.actions.path.PathDelimiter;
import net.minidev.json.actions.traverse.JSONTraverseAction;
import net.minidev.json.actions.traverse.JSONTraverser;
import net.minidev.json.actions.traverse.LocatePathsJsonAction;
import net.minidev.json.actions.traverse.RetainPathsJsonAction;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Retains branches of nodes of a {@link JSONObject} matching the list of user-specified paths.
*
* A path to copy must be specified in the n-gram format - a list of keys from the root down separated by dots:
* K0[[[[.K1].K2].K3]...]
*
* A key to the right of a dot is a direct child of a key to the left of a dot. Keys with a dot in their name are
* not supported.
*
* Example:
*
* to retain the field k1.k2 in the {@link JSONObject} {k1:{k2:v1}, k3:{k4:v2}} instantiate the retainer like so:
* new JSONObjectCleaner("k1.k2")
* The resulting object would be {k1:{k2:v1}}
*
* See unit tests in JSONObjectRetainerTest for more examples
*
* @author adoneitan@gmail.com
*/
public class PathsRetainer {
protected List pathsToRetain;
protected PathDelimiter pathDelimiter = new DotDelimiter().withAcceptDelimiterInNodeName(false);
public PathsRetainer(JSONArray pathsToRetain) {
if (pathsToRetain == null || pathsToRetain.isEmpty()) {
this.pathsToRetain = Collections.emptyList();
} else {
this.pathsToRetain = new LinkedList();
for (Object s : pathsToRetain) {
this.pathsToRetain.add((String) s);
}
}
}
public PathsRetainer(List pathsToRetain) {
this.pathsToRetain = pathsToRetain == null || pathsToRetain.size() == 0 ? Collections. emptyList() : pathsToRetain;
}
public PathsRetainer(String... pathsToRetain) {
this.pathsToRetain = pathsToRetain == null || pathsToRetain.length == 0 ? Collections. emptyList()
: new LinkedList(Arrays.asList(pathsToRetain));
}
public PathsRetainer with(PathDelimiter pathDelimiter) {
this.pathDelimiter = pathDelimiter;
return this;
}
@SuppressWarnings("unchecked")
public JSONObject retain(JSONObject object) {
/**
* a path to retain which contains a path in the object, but is not itself a path in the object,
* will cause the sub-path to be retained although it shouldn't:
* object = {k0:v0} retain = {k0.k1}
* so the false path to retain has to be removed from the pathsToRetain list.
*
* The {@link LocatePathsJsonAction} returns only paths which exist in the object.
*/
JSONTraverseAction locateAction = new LocatePathsJsonAction(pathsToRetain, pathDelimiter);
JSONTraverser t1 = new JSONTraverser(locateAction);
t1.traverse(object);
List realPathsToRetain = (List) locateAction.result();
//now reduce the object using only existing paths
JSONTraverseAction retainer = new RetainPathsJsonAction(realPathsToRetain, pathDelimiter);
JSONTraverser t2 = new JSONTraverser(retainer).with(pathDelimiter);
t2.traverse(object);
return (JSONObject) retainer.result();
}
}
netplex-json-smart-v2-20dff24/json-smart-action/src/main/java/net/minidev/json/actions/navigate/ 0000775 0000000 0000000 00000000000 14753022552 0032663 5 ustar 00root root 0000000 0000000 CopyPathsAction.java 0000664 0000000 0000000 00000006470 14753022552 0036526 0 ustar 00root root 0000000 0000000 netplex-json-smart-v2-20dff24/json-smart-action/src/main/java/net/minidev/json/actions/navigate package net.minidev.json.actions.navigate;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
import net.minidev.json.actions.path.TreePath;
import java.util.Collection;
import java.util.Stack;
/**
* Creates a copy of a {@link JSONObject} containing just the nodes on the paths specified.
*
* Specified paths that do not exist in the source object are ignored silently.
* Specifying an empty list of paths to navigate or only non-existent paths will result in an empty
* object being returned.
*
* See package-info for more details
*
* Example:
*
* To copy the branch k1.k2 from {k1:{k2:v1}, k3:{k4:v2}} instantiate the copier like so:
* new JSONObjectCopier("k1.k2")
* The resulting copy would be {k1:{k2:v1}}
*
* See unit tests for more examples
*
* @author adoneitan@gmail.com
* @since 15 March 2016.
*
*/
public class CopyPathsAction implements JSONNavigateAction {
protected JSONObject destTree;
protected JSONObject destBranch;
protected Stack