├── .github
├── FUNDING.yml
└── workflows
│ ├── build.yml
│ ├── early-access.yml
│ └── release.yml
├── .gitignore
├── LICENSE
├── README.adoc
├── SECURITY.md
├── VERSION
├── build.gradle
├── docs
└── guide
│ ├── guide.gradle
│ └── src
│ ├── docs
│ └── asciidoc
│ │ ├── _links.adoc
│ │ ├── compatibility.adoc
│ │ ├── configuration.adoc
│ │ ├── faq.adoc
│ │ ├── groovy.adoc
│ │ ├── index.adoc
│ │ ├── introduction.adoc
│ │ ├── usage.adoc
│ │ └── users.adoc
│ ├── javadoc
│ ├── overview.html
│ └── resources
│ │ └── css
│ │ └── stylesheet.css
│ └── resources
│ ├── css
│ └── style.css
│ └── images
│ └── logos
│ └── groovy-logo.png
├── gradle.properties
├── gradle
├── LICENSE_HEADER
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── jreleaser.yml
├── resources
└── images
│ └── json-lib.png
├── settings.gradle
└── subprojects
└── json-lib-core
├── json-lib-core.gradle
└── src
├── main
└── java
│ └── org
│ └── kordamp
│ └── json
│ ├── AbstractJSON.java
│ ├── JSON.java
│ ├── JSONArray.java
│ ├── JSONException.java
│ ├── JSONFunction.java
│ ├── JSONNull.java
│ ├── JSONObject.java
│ ├── JSONSerializer.java
│ ├── JSONString.java
│ ├── JsonConfig.java
│ ├── filters
│ ├── AndPropertyFilter.java
│ ├── CompositePropertyFilter.java
│ ├── FalsePropertyFilter.java
│ ├── MappingPropertyFilter.java
│ ├── NotPropertyFilter.java
│ ├── OrPropertyFilter.java
│ ├── TruePropertyFilter.java
│ └── package.html
│ ├── package.html
│ ├── processors
│ ├── DefaultDefaultValueProcessor.java
│ ├── DefaultValueProcessor.java
│ ├── DefaultValueProcessorMatcher.java
│ ├── JsDateJsonBeanProcessor.java
│ ├── JsDateJsonValueProcessor.java
│ ├── JsonBeanProcessor.java
│ ├── JsonBeanProcessorMatcher.java
│ ├── JsonValueProcessor.java
│ ├── JsonValueProcessorMatcher.java
│ ├── JsonVerifier.java
│ ├── PropertyNameProcessor.java
│ ├── PropertyNameProcessorMatcher.java
│ └── package.html
│ ├── regexp
│ ├── JdkRegexpMatcher.java
│ ├── RegexpMatcher.java
│ ├── RegexpUtils.java
│ └── package.html
│ ├── test
│ ├── JSONAssert.java
│ └── package.html
│ ├── util
│ ├── CycleDetectionStrategy.java
│ ├── EnumMorpher.java
│ ├── JSONBuilder.java
│ ├── JSONStringer.java
│ ├── JSONTokener.java
│ ├── JSONUtils.java
│ ├── JavaIdentifierTransformer.java
│ ├── JsonEventListener.java
│ ├── NewBeanInstanceStrategy.java
│ ├── PropertyExclusionClassMatcher.java
│ ├── PropertyFilter.java
│ ├── PropertySetStrategy.java
│ ├── WebHijackPreventionStrategy.java
│ ├── WebUtils.java
│ └── package.html
│ └── xml
│ ├── JSONTypes.java
│ ├── XMLSerializer.java
│ └── package.html
├── site
├── fml
│ └── faq.fml
├── resources
│ ├── css
│ │ ├── SyntaxHighlighter.css
│ │ └── maven-base2.css
│ ├── images
│ │ ├── collapsed.gif
│ │ ├── expanded.gif
│ │ ├── external.png
│ │ ├── javatoolbox.png
│ │ ├── json-lib.png
│ │ └── logos
│ │ │ ├── groovy-logo.png
│ │ │ ├── jruby-logo.png
│ │ │ └── maven-feather.png
│ └── scripts
│ │ ├── shBrushGroovy.js
│ │ ├── shBrushJScript.js
│ │ ├── shBrushJava.js
│ │ ├── shBrushRuby.js
│ │ ├── shBrushXml.js
│ │ └── shCore.js
├── site.vm
├── site.xml
└── xdoc
│ ├── advanced.xml
│ ├── features.xml
│ ├── groovy.xml
│ ├── index.xml
│ ├── package.xml
│ ├── snippets.xml
│ ├── usage.xml
│ └── users.xml
└── test
├── java
└── org
│ └── kordamp
│ └── json
│ ├── AbstractJSONArrayStaticBuildersTestCase.java
│ ├── AbstractJSONObjectStaticBuildersTestCase.java
│ ├── AbstractJSONTest.java
│ ├── AllTests.java
│ ├── Assertions.java
│ ├── JSONTestSuite.java
│ ├── PrefixerPropertyNameProcessor.java
│ ├── PropertyConstants.java
│ ├── TestGenerics.java
│ ├── TestJSONArray.java
│ ├── TestJSONArrayAsJSON.java
│ ├── TestJSONArrayAsList.java
│ ├── TestJSONArrayCollection.java
│ ├── TestJSONArrayCollections.java
│ ├── TestJSONArrayEqualsHashCodeCompareTo.java
│ ├── TestJSONArrayEvents.java
│ ├── TestJSONArrayJdk15.java
│ ├── TestJSONArrayStaticBuilders_Array_DynaBean.java
│ ├── TestJSONArrayStaticBuilders_Collection_DynaBean.java
│ ├── TestJSONArrayStaticBuilders_JSONString.java
│ ├── TestJSONArrayStaticBuilders_String.java
│ ├── TestJSONFunction.java
│ ├── TestJSONNullAsJSON.java
│ ├── TestJSONObject.java
│ ├── TestJSONObjectAsMap.java
│ ├── TestJSONObjectEqualsHashCodeCompareTo.java
│ ├── TestJSONObjectEvents.java
│ ├── TestJSONObjectJdk15.java
│ ├── TestJSONObjectStaticBuilders_DynaBean.java
│ ├── TestJSONObjectStaticBuilders_JSONObject.java
│ ├── TestJSONObjectStaticBuilders_JSONString.java
│ ├── TestJSONObjectStaticBuilders_JSONTokener.java
│ ├── TestJSONObjectStaticBuilders_Map.java
│ ├── TestJSONObjectStaticBuilders_ObjectBean.java
│ ├── TestJSONObjectStaticBuilders_PrimitiveBean.java
│ ├── TestJSONObjectStaticBuilders_String.java
│ ├── TestJSONObjectWithProcessors.java
│ ├── TestJSONSerializer.java
│ ├── TestUserSubmitted.java
│ ├── bugs
│ ├── FieldBindingTest.java
│ └── TestBug2843623.java
│ ├── filters
│ ├── AllTests.java
│ ├── TestAndPropertyFilter.java
│ ├── TestCompositePropertyFilter.java
│ ├── TestMappingPropertyFilter.java
│ ├── TestNotPropertyFilter.java
│ └── TestOrPropertyFilter.java
│ ├── processors
│ ├── AllTests.java
│ ├── StartsWithJsonBeanProcessorMatcher.java
│ ├── TestDefaultJsonBeanProcessorMatcher.java
│ ├── TestDefaultJsonValueProcessorMatcher.java
│ ├── TestDefaultPropertyNameProcessorMatcher.java
│ ├── TestDefaultValueProcessorMatcher.java
│ ├── TestJsDateJsonBeanProcessor.java
│ ├── TestJsDateJsonValueProcessor.java
│ ├── TestJsonBeanProcessorMatcher.java
│ └── TestJsonVerifier.java
│ ├── regexp
│ ├── AbstractRegexpMatcherTestCase.java
│ ├── AllTests.java
│ └── TestJdkRegexpMatcher.java
│ ├── sample
│ ├── AnnotatedBean.java
│ ├── AnnotationBean.java
│ ├── ArrayBean.java
│ ├── ArrayJSONStringBean.java
│ ├── BeanA.java
│ ├── BeanA1763699.java
│ ├── BeanB.java
│ ├── BeanB1763699.java
│ ├── BeanC.java
│ ├── BeanFoo.java
│ ├── BeanWithFunc.java
│ ├── ChildBean.java
│ ├── ClassBean.java
│ ├── DateBean.java
│ ├── EmptyBean.java
│ ├── EnumBean.java
│ ├── FieldBean.java
│ ├── GenericsBean.java
│ ├── IdBean.java
│ ├── IdentityJsonValueProcessor.java
│ ├── InterfaceBean.java
│ ├── JSONTestBean.java
│ ├── JavaIdentifierBean.java
│ ├── JsonAnnotation.java
│ ├── JsonEnum.java
│ ├── JsonEventAdpater.java
│ ├── ListingBean.java
│ ├── MappedBean.java
│ ├── MappingBean.java
│ ├── Media.java
│ ├── MediaBean.java
│ ├── MediaList.java
│ ├── MediaListBean.java
│ ├── NumberArrayBean.java
│ ├── NumberBean.java
│ ├── ObjectBean.java
│ ├── ObjectJSONStringBean.java
│ ├── PackageProtectedBean.java
│ ├── ParentBean.java
│ ├── Player.java
│ ├── PlayerList.java
│ ├── PrimitiveBean.java
│ ├── PrivateConstructorBean.java
│ ├── PropertyBean.java
│ ├── SetBean.java
│ ├── TransientBean.java
│ ├── UnstandardBean.java
│ ├── UnstandardBeanInstanceStrategy.java
│ └── ValueBean.java
│ ├── test
│ ├── AllTests.java
│ └── TestJSONAssert.java
│ ├── util
│ ├── AllTests.java
│ ├── TestDefaultPropertyExclusionClassMatcher.java
│ ├── TestJSONBuilder.java
│ ├── TestJSONStringer.java
│ ├── TestJSONTokener.java
│ ├── TestJSONUtils.java
│ ├── TestJavaIdentifierTransformer.java
│ └── TestWebUtils.java
│ └── xml
│ ├── AllTests.java
│ ├── TestArrayAutoExpansion.java
│ ├── TestAttributeWithNamespace.java
│ ├── TestElementShouldNotBeArray.java
│ ├── TestForcedArrayElementFlag.java
│ ├── TestIdmlParsing.java
│ ├── TestUserSubmitted.java
│ ├── TestXMLSerializer_reads.java
│ ├── TestXMLSerializer_writes.java
│ ├── TestXMLSerializer_writes_with_autoexpansion.java
│ ├── TestXmlContainingCData.java
│ ├── TestXmlContainingJSONSpecials.java
│ ├── TestXmlContainingTypeAttribute.java
│ └── TestXmlWithEntity.java
└── resources
└── org
└── kordamp
└── json
└── xml
├── 1735732.xml
├── 1739066.xml
├── delicious.xml
└── idml_document.idms
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | patreon: aalmiray
2 | github: aalmiray
3 | tidelift: "maven/org.kordamp.json:json-lib-core"
4 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | #
2 | # SPDX-License-Identifier: Apache-2.0
3 | #
4 | # Copyright 2006-2024 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | name: Build
20 |
21 | on:
22 | pull_request:
23 |
24 | env:
25 | JAVA_VERSION: '11'
26 | JAVA_DISTRO: 'zulu'
27 |
28 | jobs:
29 | build:
30 | name: Build
31 | runs-on: ubuntu-latest
32 | if: startsWith(github.event.head_commit.message, 'Releasing version') != true
33 |
34 | steps:
35 | - uses: actions/checkout@v4
36 |
37 | - name: Setup Java
38 | uses: actions/setup-java@v4
39 | with:
40 | java-version: ${{ env.JAVA_VERSION }}
41 | distribution: ${{ env.JAVA_DISTRO }}
42 | cache: gradle
43 |
44 | - name: Build
45 | run: ./gradlew build -S
46 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | target
3 | velocity.log
4 | cobertura.ser
5 | build.properties
6 | .classpath
7 | .project
8 | .settings
9 | build.sh
10 | build
11 | *.iml
12 | *.ipr
13 | *.iws
14 | .idea
15 | out
16 |
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | = Json-lib
2 | :linkattrs:
3 | :project-owner: kordamp
4 | :project-repo: maven
5 | :project-name: json-lib
6 | :project-group: org.kordamp.json
7 | :project-artifactId: json-lib-core
8 | :project-version: 3.1.0
9 |
10 | image:https://img.shields.io/github/actions/workflow/status/{project-owner}/{project-name}/early-access.yml?branch=master&logo=github&label=Build["Build Status", link="https://github.com/{project-owner}/{project-name}/actions"]
11 | image:https://img.shields.io/maven-central/v/{project-group}/{project-artifactId}?logo=apache%20maven[Download, link="https://search.maven.org/#search|ga|1|g:{project-group} AND a:{project-artifactId}"]
12 |
13 | ---
14 |
15 | image::resources/images/json-lib.png[]
16 |
17 | JSON-lib is a java library for transforming beans, maps, collections, java arrays and XML to JSON and back again to beans and DynaBeans.
18 |
19 | Refer to the link:http://{project-owner}.github.io/json-lib/[project guide, window="_blank"] for
20 | further information on configuration and usage.
21 |
22 | == Enterprise Support
23 |
24 | Available as part of the Tidelift Subscription.
25 |
26 | The maintainers of org.kordamp.json:json-lib-core and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for
27 | the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages
28 | you use. link:https://tidelift.com/subscription/pkg/maven-org.kordamp.json.json-lib-core?utm_source=maven-org.kordamp.json.json-lib-core&utm_medium=referral&utm_campaign=enterprise&utm_term=repo[Learn more].
29 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | ## Security contact information
2 |
3 | To report a security vulnerability, please use the
4 | [Tidelift security contact](https://tidelift.com/security).
5 | Tidelift will coordinate the fix and disclosure.
6 |
--------------------------------------------------------------------------------
/VERSION:
--------------------------------------------------------------------------------
1 | 3.2.0-SNAPSHOT
2 |
--------------------------------------------------------------------------------
/docs/guide/guide.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | plugins {
19 | id 'org.kordamp.gradle.guide'
20 | // id 'org.ajoberstar.git-publish'
21 | }
22 |
23 | configurations {
24 | asciidoctorExtensions
25 | }
26 |
27 | dependencies {
28 | asciidoctorExtensions 'com.bmuschko:asciidoctorj-tabbed-code-extension:0.3'
29 | }
30 |
31 | asciidoctor {
32 | configurations 'asciidoctorExtensions'
33 | attributes = [
34 | 'gradle-version' : project.gradle.gradleVersion,
35 | 'source-highlighter': 'prettify'
36 | ]
37 | }
38 |
--------------------------------------------------------------------------------
/docs/guide/src/docs/asciidoc/_links.adoc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/docs/guide/src/docs/asciidoc/_links.adoc
--------------------------------------------------------------------------------
/docs/guide/src/docs/asciidoc/compatibility.adoc:
--------------------------------------------------------------------------------
1 |
2 | [[_compatibility]]
3 | = Compatibility
4 |
5 | The following lists summarizes the differences between Json-lib 3.x and 2.x
6 |
7 | * All classes have moved from package `net.sf.json-lib` to `org.kordamp.json`.
8 | * JDK 8 is the new binary base line.
9 | * Java Generics have been added to method signatures.
10 |
11 |
--------------------------------------------------------------------------------
/docs/guide/src/docs/asciidoc/configuration.adoc:
--------------------------------------------------------------------------------
1 |
2 | [[_configuration]]
3 | = Build Configuration
4 |
5 | == Gradle
6 |
7 | [source,groovy,options="nowrap"]
8 | [subs="attributes"]
9 | ----
10 | dependencies {
11 | compile '{project-group}:{project-name}-core:{project-version}'
12 | }
13 | ----
14 |
15 | == Maven
16 |
17 | [source,xml,options="nowrap"]
18 | [subs="attributes,verbatim"]
19 | ----
20 |
21 | {project-group}
22 | {project-name}-core
23 | {project-version}
24 |
25 | ----
26 |
27 |
--------------------------------------------------------------------------------
/docs/guide/src/docs/asciidoc/groovy.adoc:
--------------------------------------------------------------------------------
1 | [[_groovy]]
2 | = Using Json-lib with Groovy
3 |
4 | Since version 2.0 Json-lib has integrated https://groovy-lang.org/[Groovy]
5 | support, meaning that POGOs can be transformed into JSON and back,
6 | in the same manner as you do now with POJOs. There are other features as well:
7 |
8 | * Type transformations with the `as` keyword. +
9 | A Groovy List (default type is ArrayList) can be transformed into a JSONArray. +
10 | A Groovy Map (default type is HashMap) can be transformed into a JSONObject. +
11 | A String can be transformed into JSON, JSONObject, JSONArray and JSONFunction.
12 |
13 | [source,groovy]
14 | ----
15 | def fromList = [1,true,'json'] as JSONArray
16 | def fromMap = [integer:1, bool: true] as JSONObject
17 | def strAsJson1 = "{integer:1, bool: true}" as JSON
18 | def strAsJson2 = "[1,2,3]" as JSON
19 | def strAsJsonObject = "{integer:1, bool: true}" as JSONObject
20 | def strAsJsonArray = "[1,2,3]" as JSONArray
21 | def strAsFunc = "function(param){ this.param = param; }" as JSONFunction
22 | ----
23 |
24 | * JSONObject supports the leftShift (<<) operator to append values, the
25 | following rules apply:
26 | ** If the shifted arg is a Map, it will call putAll() on the object.
27 | ** If the shifted arg is a List and its size == 2, the first element will
28 | be the key, and the second will be the value.
29 | ** If the shifted arg is a List and its size > 2, the first element will
30 | be the key, the arg will be shifted by 1 and passed as the value (wi
31 | ll create a JSONArray because it is a List).
32 | ** Any other type will be discarded, the object will not be affected nor
33 | an exception will be thrown.
34 | * JSONObject and JSONArray implement java.util.Comparable, which enables the use of
35 | the comparison operators with them (including the spaceship operator).
36 | * JSONObject implements java.util.Map and JSONArray implements java.util.List,
37 | anything you can do with Maps and List can be done with JSONObject and JSONArray.
38 | * JsonGroovyBuilder behaves like the JsonBuilder found in Grails but it will create a
39 | JSONObject/JSONArray instead of writing the built structure into a String.
40 |
41 | WARNING: Since version 2.2.1 Json-lib will not automatically enhance class through
42 | custom metaclasses, you must call GJson.enhanceClasses() before executing
43 | the examples shown on this page.
44 |
--------------------------------------------------------------------------------
/docs/guide/src/docs/asciidoc/index.adoc:
--------------------------------------------------------------------------------
1 | = Json-lib
2 | :author: {project-author}
3 | :revnumber: {project-version}
4 | :toclevels: 3
5 | :docinfo1:
6 |
7 | :toclevels: 10
8 |
9 | include::{includedir}/_links.adoc[]
10 |
11 | :leveloffset: 1
12 | include::{includedir}/introduction.adoc[]
13 | include::{includedir}/usage.adoc[]
14 | include::{includedir}/configuration.adoc[]
15 | include::{includedir}/compatibility.adoc[]
16 | include::{includedir}/groovy.adoc[]
17 | include::{includedir}/faq.adoc[]
18 |
19 | = Links
20 |
21 | link:api/index.html[Javadoc, window="_blank"]
22 |
23 | link:api-html/index.html[Source, window="_blank"]
24 |
25 | link:api-xref/index.html[Xref Source, window="_blank"]
26 |
--------------------------------------------------------------------------------
/docs/guide/src/docs/asciidoc/introduction.adoc:
--------------------------------------------------------------------------------
1 |
2 | [[_introduction]]
3 | = Introduction
4 |
5 | == Welcome to Json-lib
6 |
7 | JSON-lib is a java library for transforming beans, maps, collections, arrays and XML to JSON
8 | and back again to beans and DynaBeans. It is based on the work by Douglas Crockford in
9 | http://www.json.org/java[http://www.json.org/java, window="_blank"].
10 |
11 | The following table summarizes the types conversion between Java and JavaScript:
12 |
13 | [cols="40,10,60"]
14 | |===
15 | |JSON | |Java
16 |
17 | |string|⇔
18 | |java.lang.String, java.lang.Character, char
19 |
20 | |number | ⇔
21 | |java.lang.Number, byte, short, int, long, float, double
22 |
23 | |true/false|⇔
24 | |java.lang.Boolean, boolean
25 |
26 | |null |⇔
27 | |null
28 |
29 | |function |⇔
30 | |org.kordamp.json.JSONFunction
31 |
32 | |array|⇔
33 | |org.kordamp.json.JSONArray (object, string, number, boolean, function)
34 |
35 | |object |⇔
36 | |org.kordamp.json.JSONObject
37 |
38 | |===
39 |
40 | The `function` type from JavaScript is not part of the JSON
41 | format "officially" (please refer to http://www.json.org[http://www.json.org])
42 | but it is supported as well.
43 |
44 | Json-lib requires (at least) the following dependencies in your classpath:
45 |
46 | * Apache commons-lang3 3.9
47 | * Apache commons-beanutils 1.9.3
48 | * Apache commons-collections4 4.4
49 | * slf4j 1.7.30
50 | * ezmorph 3.0.0
51 |
52 | Other dependencies are needed if working with XML:
53 |
54 | * xom 1.3.5
55 |
56 | == What is JSON
57 |
58 | JSON (JavaScript Object Notation) is a lightweight
59 | data-interchange format. It is easy for humans to read
60 | and write. It is easy for machines to parse and
61 | generate. It is based on a subset of the JavaScript
62 | Programming Language, Standard ECMA-262 3rd Edition -
63 | December 1999. JSON is a text format that is completely
64 | language independent but uses conventions that are
65 | familiar to programmers of the C-family of languages,
66 | including C, C++, C#, Java, JavaScript, Perl, Python,
67 | and many others.
68 |
69 | These properties make JSON an ideal data-interchange
70 | language.
71 |
72 | NOTE: Documentation for older releases can be found at link:http://json-lib.sourceforge.net/[]
73 |
--------------------------------------------------------------------------------
/docs/guide/src/javadoc/overview.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Json-lib
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/docs/guide/src/resources/images/logos/groovy-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/docs/guide/src/resources/images/logos/groovy-logo.png
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # SPDX-License-Identifier: Apache-2.0
3 | #
4 | # Copyright 2006-2024 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | group = org.kordamp.json
20 | sourceCompatibility = 1.8
21 | targetCompatibility = 1.8
22 |
23 | commonsLangVersion = 3.14.0
24 | commonsBeanutilsVersion = 1.9.3
25 | commonsCollections4Version = 4.4
26 | ezmorphVersion = 3.1.0
27 | jacocoVersion = 0.8.12
28 | junitVersion = 4.13.2
29 | slf4jVersion = 2.0.13
30 | slf4jTestVersion = 3.0.1
31 | xmlunitVersion = 2.10.0
32 | xomVersion = 1.3.9
33 |
34 | kordampPluginVersion = 0.54.0
35 | kordampBuildVersion = 3.4.0
36 | gitPluginVersion = 3.0.0
37 | cyclonedxPluginVersion = 1.8.2
38 |
39 | org.gradle.daemon = true
40 | org.gradle.caching = true
41 | org.gradle.parallel = false
42 |
--------------------------------------------------------------------------------
/gradle/LICENSE_HEADER:
--------------------------------------------------------------------------------
1 | SPDX-License-Identifier: Apache-2.0
2 |
3 | Copyright ${copyrightYear} the original author or authors.
4 |
5 | Licensed under the Apache License, Version 2.0 (the "License");
6 | you may not use this file except in compliance with the License.
7 | You may obtain a copy of the License at
8 |
9 | https://www.apache.org/licenses/LICENSE-2.0
10 |
11 | Unless required by applicable law or agreed to in writing, software
12 | distributed under the License is distributed on an "AS IS" BASIS,
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | See the License for the specific language governing permissions and
15 | limitations under the License.
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/resources/images/json-lib.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/resources/images/json-lib.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | pluginManagement {
19 | repositories {
20 | gradlePluginPortal()
21 | mavenCentral()
22 | mavenLocal()
23 | }
24 | plugins {
25 | id 'org.kordamp.gradle.guide' version kordampPluginVersion
26 | id 'org.ajoberstar.git-publish' version gitPluginVersion
27 | }
28 | }
29 |
30 | buildscript {
31 | repositories {
32 | gradlePluginPortal()
33 | mavenCentral()
34 | mavenLocal()
35 | }
36 | dependencies {
37 | classpath "org.kordamp.gradle:kordamp-parentbuild:$kordampBuildVersion"
38 | classpath "org.cyclonedx:cyclonedx-gradle-plugin:$cyclonedxPluginVersion"
39 | }
40 | }
41 | apply plugin: 'org.kordamp.gradle.kordamp-parentbuild'
42 |
43 | rootProject.name = 'json-lib'
44 |
45 | projects {
46 | directories = ['docs', 'subprojects']
47 |
48 | plugins {
49 | all {
50 | id 'base'
51 | id 'idea'
52 | }
53 | path(':') {
54 | id 'org.kordamp.gradle.java-project'
55 | }
56 | dirs(['subprojects']) {
57 | id 'java-library'
58 | id 'org.cyclonedx.bom'
59 | }
60 | }
61 | }
62 |
63 | enforce {
64 | rule(enforcer.rules.ExcludeDependencies) { r ->
65 | r.exclude('commons-logging:commons-logging')
66 | r.exclude('org.slf4j:slf4j-compile')
67 | }
68 | rule(enforcer.rules.ForceDependencies) { r ->
69 | r.dependencies.addAll 'xml-apis:xml-apis:2.0.2',
70 | "org.apache.commons:commons-lang3:$commonsLangVersion",
71 | "org.slf4j:slf4j-api:$slf4jVersion",
72 | "junit:junit:$junitVersion",
73 | "commons-beanutils:commons-beanutils:$commonsBeanutilsVersion",
74 | "org.slf4j:jcl-over-slf4j:$slf4jVersion"
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/json-lib-core.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | dependencies {
19 | api("junit:junit:$junitVersion")
20 | api("commons-beanutils:commons-beanutils:$commonsBeanutilsVersion")
21 | api("org.apache.commons:commons-collections4:$commonsCollections4Version")
22 | api("org.apache.commons:commons-lang3:$commonsLangVersion")
23 |
24 | api("org.slf4j:slf4j-api:$slf4jVersion")
25 | api("org.slf4j:jcl-over-slf4j:$slf4jVersion")
26 |
27 | // the following should be marked as optional
28 | api("xom:xom:$xomVersion")
29 | api("org.kordamp.ezmorph:ezmorph-core:$ezmorphVersion")
30 |
31 | testImplementation("org.xmlunit:xmlunit-legacy:$xmlunitVersion")
32 | testImplementation("com.github.valfirst:slf4j-test:$slf4jTestVersion")
33 | }
34 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/JSONException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | /**
21 | * The JSONException is thrown when things are amiss.
22 | *
23 | * @author JSON.org
24 | * @version 4
25 | */
26 | public class JSONException extends RuntimeException {
27 | private static final long serialVersionUID = -359505426467944084L;
28 |
29 | public JSONException() {
30 | super();
31 | }
32 |
33 | public JSONException(String msg) {
34 | super(msg, null);
35 | }
36 |
37 | public JSONException(String msg, Throwable cause) {
38 | super(msg, cause);
39 | }
40 |
41 | public JSONException(Throwable cause) {
42 | super((cause == null ? null : cause.toString()), cause);
43 | }
44 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/JSONString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | /**
21 | * The JSONString interface allows a toJSONString()
22 | * method so that a class can change the behavior of
23 | * JSONObject.toString(), JSONArray.toString(),
24 | * and JSONWriter.value(Object). The
25 | * toJSONString method will be used instead of the default
26 | * behavior of using the Object's toString() method and quoting
27 | * the result.
28 | */
29 | public interface JSONString {
30 | /**
31 | * The toJSONString method allows a class to produce its own
32 | * JSON serialization.
33 | *
34 | * @return A strictly syntactically correct JSON text.
35 | */
36 | String toJSONString();
37 | }
38 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/filters/AndPropertyFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.filters;
19 |
20 | import org.kordamp.json.util.PropertyFilter;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class AndPropertyFilter implements PropertyFilter {
26 | private PropertyFilter filter1;
27 | private PropertyFilter filter2;
28 |
29 | public AndPropertyFilter(PropertyFilter filter1, PropertyFilter filter2) {
30 | this.filter1 = filter1;
31 | this.filter2 = filter2;
32 | }
33 |
34 | public boolean apply(Object source, String name, Object value) {
35 | if (filter1 != null && filter1.apply(source, name, value) && filter2 != null
36 | && filter2.apply(source, name, value)) {
37 | return true;
38 | }
39 | return false;
40 | }
41 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/filters/CompositePropertyFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.filters;
19 |
20 | import org.kordamp.json.util.PropertyFilter;
21 |
22 | import java.util.ArrayList;
23 | import java.util.Iterator;
24 | import java.util.List;
25 |
26 | /**
27 | * @author Andres Almiray
28 | */
29 | public class CompositePropertyFilter implements PropertyFilter {
30 | private List filters = new ArrayList();
31 |
32 | public CompositePropertyFilter() {
33 | this(null);
34 | }
35 |
36 | public CompositePropertyFilter(List filters) {
37 | if (filters != null) {
38 | for (Iterator i = filters.iterator(); i.hasNext(); ) {
39 | Object filter = i.next();
40 | if (filter instanceof PropertyFilter && !this.filters.contains(filter)) {
41 | this.filters.add(filter);
42 | }
43 | }
44 | }
45 | }
46 |
47 | public void addPropertyFilter(PropertyFilter filter) {
48 | if (filter != null && !this.filters.contains(filter)) {
49 | filters.add(filter);
50 | }
51 | }
52 |
53 | public boolean apply(Object source, String name, Object value) {
54 | for (Iterator i = filters.iterator(); i.hasNext(); ) {
55 | PropertyFilter filter = (PropertyFilter) i.next();
56 | if (filter.apply(source, name, value)) {
57 | return true;
58 | }
59 | }
60 | return false;
61 | }
62 |
63 | public void removePropertyFilter(PropertyFilter filter) {
64 | if (filter != null) {
65 | filters.remove(filter);
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/filters/FalsePropertyFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.filters;
19 |
20 | import org.kordamp.json.util.PropertyFilter;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class FalsePropertyFilter implements PropertyFilter {
26 | public boolean apply(Object source, String name, Object value) {
27 | return false;
28 | }
29 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/filters/NotPropertyFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.filters;
19 |
20 | import org.kordamp.json.util.PropertyFilter;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class NotPropertyFilter implements PropertyFilter {
26 | private PropertyFilter filter;
27 |
28 | public NotPropertyFilter(PropertyFilter filter) {
29 | this.filter = filter;
30 | }
31 |
32 | public boolean apply(Object source, String name, Object value) {
33 | if (filter != null) {
34 | return !filter.apply(source, name, value);
35 | }
36 | return false;
37 | }
38 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/filters/OrPropertyFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.filters;
19 |
20 | import org.kordamp.json.util.PropertyFilter;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class OrPropertyFilter implements PropertyFilter {
26 | private PropertyFilter filter1;
27 | private PropertyFilter filter2;
28 |
29 | public OrPropertyFilter(PropertyFilter filter1, PropertyFilter filter2) {
30 | this.filter1 = filter1;
31 | this.filter2 = filter2;
32 | }
33 |
34 | public boolean apply(Object source, String name, Object value) {
35 | if ((filter1 != null && filter1.apply(source, name, value))
36 | || (filter2 != null && filter2.apply(source, name, value))) {
37 | return true;
38 | }
39 | return false;
40 | }
41 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/filters/TruePropertyFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.filters;
19 |
20 | import org.kordamp.json.util.PropertyFilter;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class TruePropertyFilter implements PropertyFilter {
26 | public boolean apply(Object source, String name, Object value) {
27 | return true;
28 | }
29 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/filters/package.html:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/DefaultDefaultValueProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import org.kordamp.json.JSONArray;
21 | import org.kordamp.json.JSONNull;
22 | import org.kordamp.json.util.JSONUtils;
23 |
24 | /**
25 | * Base implementation for DefaultDefaultValueProcessor.
26 | *
27 | * @author Andres Almiray
28 | */
29 | public class DefaultDefaultValueProcessor implements DefaultValueProcessor {
30 | public Object getDefaultValue(Class type) {
31 | if (JSONUtils.isArray(type)) {
32 | return new JSONArray();
33 | } else if (JSONUtils.isNumber(type)) {
34 | if (JSONUtils.isDouble(type)) {
35 | return new Double(0);
36 | } else {
37 | return new Integer(0);
38 | }
39 | } else if (JSONUtils.isBoolean(type)) {
40 | return Boolean.FALSE;
41 | } else if (JSONUtils.isString(type)) {
42 | return "";
43 | }
44 | return JSONNull.getInstance();
45 | }
46 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/DefaultValueProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | /**
21 | * Defines the default value for a type when its value is null.
22 | *
23 | * @author Andres Almiray
24 | */
25 | public interface DefaultValueProcessor {
26 | /**
27 | * Returns an appropriate default value for a type.
28 | *
29 | * @param type
30 | *
31 | * @return the default value for instances of type
32 | */
33 | Object getDefaultValue(Class type);
34 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/DefaultValueProcessorMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import java.util.Set;
21 |
22 | /**
23 | * Base class for finding a matching DefaultValueProcessor.
24 | *
25 | *
DEFAULT - matches the target class with equals().
26 | *
27 | *
28 | * @author Andres Almiray
29 | */
30 | public abstract class DefaultValueProcessorMatcher {
31 | /**
32 | * Matches the target with equals()
33 | */
34 | public static final DefaultValueProcessorMatcher DEFAULT = new DefaultDefaultValueProcessorMatcher();
35 |
36 | /**
37 | * Returns the matching class calculated with the target class and the
38 | * provided set.
39 | *
40 | * @param target the target class to match
41 | * @param set a set of possible matches
42 | */
43 | public abstract Object getMatch(Class target, Set set);
44 |
45 | private static final class DefaultDefaultValueProcessorMatcher extends
46 | DefaultValueProcessorMatcher {
47 | public Object getMatch(Class target, Set set) {
48 | if (target != null && set != null && set.contains(target)) {
49 | return target;
50 | }
51 | return null;
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/JsDateJsonBeanProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import org.kordamp.json.JSONObject;
21 | import org.kordamp.json.JsonConfig;
22 |
23 | import java.util.Calendar;
24 | import java.util.Date;
25 |
26 | /**
27 | * Transforms a java.util.Date into a JSONObject ideal for JsDate conversion.
28 | * Example:
29 | *
30 | *
41 | *
42 | * @author Andres Almiray
43 | */
44 | public class JsDateJsonBeanProcessor implements JsonBeanProcessor {
45 |
46 | /**
47 | * Processes the input bean into a compatible JsDate.
48 | */
49 | public JSONObject processBean(Object bean, JsonConfig jsonConfig) {
50 | JSONObject jsonObject = null;
51 | if (bean instanceof java.sql.Date) {
52 | bean = new Date(((java.sql.Date) bean).getTime());
53 | }
54 | if (bean instanceof Date) {
55 | Calendar c = Calendar.getInstance();
56 | c.setTime((Date) bean);
57 | jsonObject = new JSONObject().element("year", c.get(Calendar.YEAR))
58 | .element("month", c.get(Calendar.MONTH))
59 | .element("day", c.get(Calendar.DAY_OF_MONTH))
60 | .element("hours", c.get(Calendar.HOUR_OF_DAY))
61 | .element("minutes", c.get(Calendar.MINUTE))
62 | .element("seconds", c.get(Calendar.SECOND))
63 | .element("milliseconds", c.get(Calendar.MILLISECOND));
64 | } else {
65 | jsonObject = new JSONObject(true);
66 | }
67 | return jsonObject;
68 | }
69 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/JsDateJsonValueProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import org.kordamp.json.JsonConfig;
21 |
22 | /**
23 | * Transforms a java.util.Date property into a JSONObject ideal for JsDate
24 | * conversion
25 | *
26 | * @author Andres Almiray
27 | */
28 | public class JsDateJsonValueProcessor implements JsonValueProcessor {
29 |
30 | private JsonBeanProcessor processor;
31 |
32 | public JsDateJsonValueProcessor() {
33 | processor = new JsDateJsonBeanProcessor();
34 | }
35 |
36 | public Object processArrayValue(Object value, JsonConfig jsonConfig) {
37 | return process(value, jsonConfig);
38 | }
39 |
40 | public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {
41 | return process(value, jsonConfig);
42 | }
43 |
44 | private Object process(Object value, JsonConfig jsonConfig) {
45 | return processor.processBean(value, jsonConfig);
46 | }
47 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/JsonBeanProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import org.kordamp.json.JSONObject;
21 | import org.kordamp.json.JsonConfig;
22 |
23 | /**
24 | * Base interface for custom serialization per Bean.
25 | *
26 | * @author Andres Almiray
27 | */
28 | public interface JsonBeanProcessor {
29 | /**
30 | * Processes the bean an returns a suitable JSONObject representation.
31 | *
32 | * @param bean the input bean
33 | * @param jsonConfig the current configuration environment
34 | *
35 | * @return a JSONObject that represents the input bean
36 | *
37 | * @throws org.kordamp.json.JSONException if an error occurs during transformation
38 | */
39 | JSONObject processBean(Object bean, JsonConfig jsonConfig);
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/JsonBeanProcessorMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import java.util.Set;
21 |
22 | /**
23 | * Base class for finding a matching JsonBeanProcessor.
24 | *
25 | *
DEFAULT - matches the target class with equals().
26 | *
27 | *
28 | * @author Andres Almiray
29 | */
30 | public abstract class JsonBeanProcessorMatcher {
31 | /**
32 | * Matches the target with equals()
33 | */
34 | public static final JsonBeanProcessorMatcher DEFAULT = new DefaultJsonBeanProcessorMatcher();
35 |
36 | /**
37 | * Returns the matching class calculated with the target class and the
38 | * provided set.
39 | *
40 | * @param target the target class to match
41 | * @param set a set of possible matches
42 | */
43 | public abstract Object getMatch(Class target, Set set);
44 |
45 | private static final class DefaultJsonBeanProcessorMatcher extends JsonBeanProcessorMatcher {
46 | public Object getMatch(Class target, Set set) {
47 | if (target != null && set != null && set.contains(target)) {
48 | return target;
49 | }
50 | return null;
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/JsonValueProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import org.kordamp.json.JsonConfig;
21 |
22 | /**
23 | * Base interface for custom serialization per property.
24 | *
25 | * @author Andres Almiray
26 | */
27 | public interface JsonValueProcessor {
28 | /**
29 | * Processes the value an returns a suitable JSON value.
30 | *
31 | * @param value the input value
32 | *
33 | * @return a valid JSON value that represents the input value
34 | *
35 | * @throws org.kordamp.json.JSONException if an error occurs during transformation
36 | */
37 | Object processArrayValue(Object value, JsonConfig jsonConfig);
38 |
39 | /**
40 | * Processes the value an returns a suitable JSON value.
41 | *
42 | * @param key the name of the property
43 | * @param value the value of the property
44 | *
45 | * @return a valid JSON value that represents the input property
46 | *
47 | * @throws org.kordamp.json.JSONException if an error occurs during transformation
48 | */
49 | Object processObjectValue(String key, Object value, JsonConfig jsonConfig);
50 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/JsonValueProcessorMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import java.util.Set;
21 |
22 | /**
23 | * Base class for finding a matching JsonValueProcessor.
24 | *
25 | *
DEFAULT - matches the target class with equals().
26 | *
27 | *
28 | * @author Andres Almiray
29 | */
30 | public abstract class JsonValueProcessorMatcher {
31 | /**
32 | * Matches the target with equals()
33 | */
34 | public static final JsonValueProcessorMatcher DEFAULT = new DefaultJsonValueProcessorMatcher();
35 |
36 | /**
37 | * Returns the matching class calculated with the target class and the
38 | * provided set.
39 | *
40 | * @param target the target class to match
41 | * @param set a set of possible matches
42 | */
43 | public abstract Object getMatch(Class target, Set set);
44 |
45 | private static final class DefaultJsonValueProcessorMatcher extends JsonValueProcessorMatcher {
46 | public Object getMatch(Class target, Set set) {
47 | if (target != null && set != null && set.contains(target)) {
48 | return target;
49 | }
50 | return null;
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/JsonVerifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import org.kordamp.json.JSON;
21 | import org.kordamp.json.JSONFunction;
22 | import org.kordamp.json.JSONNull;
23 | import org.kordamp.json.JSONString;
24 |
25 | import java.math.BigDecimal;
26 | import java.math.BigInteger;
27 |
28 | /**
29 | * Verifies if a value is a valid JSON value.
30 | *
31 | * @author Andres Almiray
32 | */
33 | public final class JsonVerifier {
34 |
35 | /**
36 | * Verifies if value is a valid JSON value.
37 | *
38 | * @param value the value to verify
39 | */
40 | public static boolean isValidJsonValue(Object value) {
41 | if (JSONNull.getInstance()
42 | .equals(value) || value instanceof JSON || value instanceof Boolean
43 | || value instanceof Byte || value instanceof Short
44 | || value instanceof Integer || value instanceof Long || value instanceof Double
45 | || value instanceof BigInteger || value instanceof BigDecimal
46 | || value instanceof JSONFunction || value instanceof JSONString
47 | || value instanceof String) {
48 | return true;
49 | }
50 | return false;
51 | }
52 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/PropertyNameProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 |
21 | /**
22 | * Base interface for mutating property names of a Bean.
23 | *
24 | * @author Andres Almiray
25 | */
26 | public interface PropertyNameProcessor {
27 | /**
28 | * Processes the property name.
29 | *
30 | * @param beanClass the input bean's class
31 | * @param name the current property name
32 | *
33 | * @return an updated property name
34 | */
35 | String processPropertyName(Class beanClass, String name);
36 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/PropertyNameProcessorMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import java.util.Set;
21 |
22 | /**
23 | * Base class for finding a matching PropertyNameProcessor.
24 | *
25 | *
DEFAULT - matches the target class with equals().
26 | *
27 | *
28 | * @author Andres Almiray
29 | */
30 | public abstract class PropertyNameProcessorMatcher {
31 | /**
32 | * Matches the target with equals()
33 | */
34 | public static final PropertyNameProcessorMatcher DEFAULT = new DefaultPropertyNameProcessorMatcher();
35 |
36 | /**
37 | * Returns the matching class calculated with the target class and the
38 | * provided set.
39 | *
40 | * @param target the target class to match
41 | * @param set a set of possible matches
42 | */
43 | public abstract Object getMatch(Class target, Set set);
44 |
45 | private static final class DefaultPropertyNameProcessorMatcher extends PropertyNameProcessorMatcher {
46 | public Object getMatch(Class target, Set set) {
47 | if (target != null && set != null && set.contains(target)) {
48 | return target;
49 | }
50 | return null;
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/processors/package.html:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
24 |
25 |
Support for custom serialization
26 |
27 |
28 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/regexp/JdkRegexpMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.regexp;
19 |
20 | import java.util.regex.Matcher;
21 | import java.util.regex.Pattern;
22 |
23 | /**
24 | * JDK 1.4+ RegexpMatcher implementation.
25 | *
26 | * @author Andres Almiray
27 | */
28 | public class JdkRegexpMatcher implements RegexpMatcher {
29 | private final Pattern pattern;
30 |
31 | public JdkRegexpMatcher(String pattern) {
32 | this(pattern, false);
33 | }
34 |
35 | public JdkRegexpMatcher(String pattern, boolean multiline) {
36 | if (multiline) {
37 | this.pattern = Pattern.compile(pattern, Pattern.MULTILINE);
38 | } else {
39 | this.pattern = Pattern.compile(pattern);
40 | }
41 | }
42 |
43 | public String getGroupIfMatches(String str, int group) {
44 | Matcher matcher = pattern.matcher(str);
45 | if (matcher.matches()) {
46 | return matcher.group(group);
47 | }
48 | return "";
49 | }
50 |
51 | public boolean matches(String str) {
52 | return pattern.matcher(str).matches();
53 | }
54 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/regexp/RegexpMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.regexp;
19 |
20 | /**
21 | * Abstraction for regexp handling.
22 | *
23 | * @author Andres Almiray
24 | */
25 | public interface RegexpMatcher {
26 | /**
27 | * Returns the specified group if the string matches the Pattern.
28 | * The Pattern will be managed internally by the RegexpMatcher
29 | * implementation.
30 | */
31 | String getGroupIfMatches(String str, int group);
32 |
33 | /**
34 | * Returns true is the string matches the Pattern.
35 | * The Pattern will be managed internally by the RegexpMatcher
36 | * implementation.
37 | */
38 | boolean matches(String str);
39 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/regexp/RegexpUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.regexp;
19 |
20 | /**
21 | * Convenience utility for working withRegexpMatcher.
22 | *
23 | * @author Andres Almiray
24 | */
25 | public class RegexpUtils {
26 | private RegexpUtils() {
27 |
28 | }
29 |
30 | /**
31 | * Returns a RegexpMatcher that works in a specific environment.
32 | */
33 | public static RegexpMatcher getMatcher(String pattern) {
34 | return new JdkRegexpMatcher(pattern);
35 | }
36 |
37 | /**
38 | * Returns a RegexpMatcher that works in a specific environment.
39 | */
40 | public static RegexpMatcher getMatcher(String pattern, boolean multiline) {
41 | return new JdkRegexpMatcher(pattern, multiline);
42 | }
43 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/regexp/package.html:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/util/EnumMorpher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.util;
19 |
20 | import org.kordamp.ezmorph.ObjectMorpher;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class EnumMorpher implements ObjectMorpher {
26 | private Class enumClass;
27 |
28 | public EnumMorpher(Class enumClass) {
29 | if (enumClass == null) {
30 | throw new IllegalArgumentException("enumClass is null");
31 | }
32 | if (!Enum.class.isAssignableFrom(enumClass)) {
33 | throw new IllegalArgumentException("enumClass is not an Enum class");
34 | }
35 | this.enumClass = enumClass;
36 | }
37 |
38 | public Object morph(Object value) {
39 | if (value == null) {
40 | return enumClass.cast(null);
41 | }
42 | return Enum.valueOf(enumClass, String.valueOf(value));
43 | }
44 |
45 | public Class morphsTo() {
46 | return enumClass;
47 | }
48 |
49 | public boolean supports(Class clazz) {
50 | return String.class.isAssignableFrom(clazz);
51 | }
52 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/util/PropertyExclusionClassMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.util;
19 |
20 | import java.util.Set;
21 |
22 | /**
23 | * Base class for finding a matching property exlucsion.
24 | *
25 | *
DEFAULT - matches the target class with equals().
26 | *
27 | *
28 | * @author Andres Almiray
29 | */
30 | public abstract class PropertyExclusionClassMatcher {
31 | /**
32 | * Matches the target with equals()
33 | */
34 | public static final PropertyExclusionClassMatcher DEFAULT = new DefaultPropertyExclusionClassMatcher();
35 |
36 | /**
37 | * Returns the matching class calculated with the target class and the
38 | * provided set.
39 | *
40 | * @param target the target class to match
41 | * @param set a set of possible matches
42 | */
43 | public abstract Object getMatch(Class target, Set set);
44 |
45 | private static final class DefaultPropertyExclusionClassMatcher extends PropertyExclusionClassMatcher {
46 | public Object getMatch(Class target, Set set) {
47 | if (target != null && set != null && set.contains(target)) {
48 | return target;
49 | }
50 | return null;
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/util/PropertyFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.util;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public interface PropertyFilter {
24 | /**
25 | * @param source the owner of the property
26 | * @param name the name of the property
27 | * @param value the value of the property
28 | *
29 | * @return true if the property will be filtered out, false otherwise
30 | */
31 | boolean apply(Object source, String name, Object value);
32 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/util/WebHijackPreventionStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.util;
19 |
20 | /**
21 | * Defines base implementations for preventing WebHijack in AJAX applications.
22 | * The default implementations are:
23 | *
24 | *
COMMENTS - wraps the string with /* *\/
25 | *
INFINITE_LOOP - prepends "while(1);"
26 | *
27 | *
28 | * @author Andres Almiray
29 | */
30 | public abstract class WebHijackPreventionStrategy {
31 | /**
32 | * Wraps the string with /* *\/
33 | */
34 | public static final WebHijackPreventionStrategy COMMENTS = new CommentWebHijackPreventionStrategy();
35 | /**
36 | * Prepends "while(1);"
37 | */
38 | public static final WebHijackPreventionStrategy INFINITE_LOOP = new InfiniteLoopWebHijackPreventionStrategy();
39 |
40 | /**
41 | * Transforms the input with the desired strategy.
42 | *
43 | * @param str a json string
44 | *
45 | * @return String - the transformed json string
46 | */
47 | public abstract String protect(String str);
48 |
49 | private static final class CommentWebHijackPreventionStrategy extends
50 | WebHijackPreventionStrategy {
51 | public String protect(String str) {
52 | return "/*" + str + "*/";
53 | }
54 | }
55 |
56 | private static final class InfiniteLoopWebHijackPreventionStrategy extends
57 | WebHijackPreventionStrategy {
58 | public String protect(String str) {
59 | return "while(1);" + str;
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/util/package.html:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
24 |
25 |
Miscelaneous utilities
26 |
27 |
28 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/xml/JSONTypes.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.xml;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public interface JSONTypes {
24 | String ARRAY = "array";
25 | String BOOLEAN = "boolean";
26 | String FLOAT = "float";
27 | String FUNCTION = "function";
28 | String INTEGER = "integer";
29 | String NUMBER = "number";
30 | String OBJECT = "object";
31 | String STRING = "string";
32 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/main/java/org/kordamp/json/xml/package.html:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
23 |
24 |
25 |
Utilities for trasforming JSON to XML and back.
26 |
27 |
28 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/images/collapsed.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/subprojects/json-lib-core/src/site/resources/images/collapsed.gif
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/images/expanded.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/subprojects/json-lib-core/src/site/resources/images/expanded.gif
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/images/external.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/subprojects/json-lib-core/src/site/resources/images/external.png
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/images/javatoolbox.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/subprojects/json-lib-core/src/site/resources/images/javatoolbox.png
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/images/json-lib.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/subprojects/json-lib-core/src/site/resources/images/json-lib.png
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/images/logos/groovy-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/subprojects/json-lib-core/src/site/resources/images/logos/groovy-logo.png
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/images/logos/jruby-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/subprojects/json-lib-core/src/site/resources/images/logos/jruby-logo.png
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/images/logos/maven-feather.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kordamp/json-lib/db76e697a568c553af19de01c8a9b12b85222183/subprojects/json-lib-core/src/site/resources/images/logos/maven-feather.png
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/scripts/shBrushJScript.js:
--------------------------------------------------------------------------------
1 | dp.sh.Brushes.JScript = function () {
2 | var keywords = 'abstract boolean break byte case catch char class const continue debugger ' +
3 | 'default delete do double else enum export extends false final finally float ' +
4 | 'for function goto if implements import in instanceof int interface long native ' +
5 | 'new null package private protected public return short static super switch ' +
6 | 'synchronized this throw throws transient true try typeof var void volatile while with';
7 |
8 | this.regexList = [
9 | {regex: dp.sh.RegexLib.SingleLineCComments, css: 'comment'}, // one line comments
10 | {regex: dp.sh.RegexLib.MultiLineCComments, css: 'comment'}, // multiline comments
11 | {regex: dp.sh.RegexLib.DoubleQuotedString, css: 'string'}, // double quoted strings
12 | {regex: dp.sh.RegexLib.SingleQuotedString, css: 'string'}, // single quoted strings
13 | {regex: new RegExp('^\\s*#.*', 'gm'), css: 'preprocessor'}, // preprocessor tags like #region and #endregion
14 | {regex: new RegExp(this.GetKeywords(keywords), 'gm'), css: 'keyword'} // keywords
15 | ];
16 |
17 | this.CssClass = 'dp-c';
18 | }
19 |
20 | dp.sh.Brushes.JScript.prototype = new dp.sh.Highlighter();
21 | dp.sh.Brushes.JScript.Aliases = ['js', 'jscript', 'javascript'];
22 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/scripts/shBrushJava.js:
--------------------------------------------------------------------------------
1 | dp.sh.Brushes.Java = function () {
2 | var keywords = 'abstract assert boolean break byte case catch char class const ' +
3 | 'continue default do double else enum extends ' +
4 | 'false final finally float for goto if implements import ' +
5 | 'instanceof int interface long native new null ' +
6 | 'package private protected public return ' +
7 | 'short static strictfp super switch synchronized this throw throws true ' +
8 | 'transient try void volatile while';
9 |
10 | this.regexList = [
11 | {regex: dp.sh.RegexLib.SingleLineCComments, css: 'comment'}, // one line comments
12 | {regex: dp.sh.RegexLib.MultiLineCComments, css: 'comment'}, // multiline comments
13 | {regex: dp.sh.RegexLib.DoubleQuotedString, css: 'string'}, // strings
14 | {regex: dp.sh.RegexLib.SingleQuotedString, css: 'string'}, // strings
15 | {regex: new RegExp('\\b([\\d]+(\\.[\\d]+)?|0x[a-f0-9]+)\\b', 'gi'), css: 'number'}, // numbers
16 | {regex: new RegExp('(?!\\@interface\\b)\\@[\\$\\w]+\\b', 'g'), css: 'annotation'}, // annotation @anno
17 | {regex: new RegExp('\\@interface\\b', 'g'), css: 'keyword'}, // @interface keyword
18 | {regex: new RegExp(this.GetKeywords(keywords), 'gm'), css: 'keyword'} // java keyword
19 | ];
20 |
21 | this.CssClass = 'dp-j';
22 | }
23 |
24 | dp.sh.Brushes.Java.prototype = new dp.sh.Highlighter();
25 | dp.sh.Brushes.Java.Aliases = ['java'];
26 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/scripts/shBrushRuby.js:
--------------------------------------------------------------------------------
1 | /* Ruby 1.8.4 syntax contributed by Erik Peterson */
2 | dp.sh.Brushes.Ruby = function () {
3 | var keywords = 'alias and BEGIN begin break case class def define_method defined do each else elsif ' +
4 | 'END end ensure false for if in module new next nil not or raise redo rescue retry return ' +
5 | 'self super then throw true undef unless until when while yield';
6 |
7 | var builtins = 'Array Bignum Binding Class Continuation Dir Exception FalseClass File::Stat File Fixnum Fload ' +
8 | 'Hash Integer IO MatchData Method Module NilClass Numeric Object Proc Range Regexp String Struct::TMS Symbol ' +
9 | 'ThreadGroup Thread Time TrueClass'
10 |
11 | this.regexList = [
12 | {regex: dp.sh.RegexLib.SingleLinePerlComments, css: 'comment'}, // one line comments
13 | {regex: dp.sh.RegexLib.DoubleQuotedString, css: 'string'}, // double quoted strings
14 | {regex: dp.sh.RegexLib.SingleQuotedString, css: 'string'}, // single quoted strings
15 | {regex: new RegExp(':[a-z][A-Za-z0-9_]*', 'g'), css: 'symbol'}, // symbols
16 | {regex: new RegExp('[\\$|@|@@]\\w+', 'g'), css: 'variable'}, // $global, @instance, and @@class variables
17 | {regex: new RegExp(this.GetKeywords(keywords), 'gm'), css: 'keyword'}, // keywords
18 | {regex: new RegExp(this.GetKeywords(builtins), 'gm'), css: 'builtin'} // builtins
19 | ];
20 |
21 | this.CssClass = 'dp-rb';
22 | }
23 |
24 | dp.sh.Brushes.Ruby.prototype = new dp.sh.Highlighter();
25 | dp.sh.Brushes.Ruby.Aliases = ['ruby', 'rails'];
26 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/resources/scripts/shBrushXml.js:
--------------------------------------------------------------------------------
1 | dp.sh.Brushes.Xml = function () {
2 | this.CssClass = 'dp-xml';
3 | }
4 |
5 | dp.sh.Brushes.Xml.prototype = new dp.sh.Highlighter();
6 | dp.sh.Brushes.Xml.Aliases = ['xml', 'xhtml', 'xslt', 'html', 'xhtml'];
7 |
8 | dp.sh.Brushes.Xml.prototype.ProcessRegexList = function () {
9 | function push(array, value) {
10 | array[array.length] = value;
11 | }
12 |
13 | /* If only there was a way to get index of a group within a match, the whole XML
14 | could be matched with the expression looking something like that:
15 |
16 | ()
17 | | ()
18 | | (<)*(\w+)*\s*(\w+)\s*=\s*(".*?"|'.*?'|\w+)(/*>)*
19 | | (?)(.*?)(/?>)
20 | */
21 | var index = 0;
22 | var match = null;
23 | var regex = null;
24 |
25 | // Match CDATA in the following format
26 | // <\!\[[\w\s]*?\[(.|\s)*?\]\]>
27 | this.GetMatches(new RegExp('<\\!\\[[\\w\\s]*?\\[(.|\\s)*?\\]\\]>', 'gm'), 'cdata');
28 |
29 | // Match comments
30 | //
31 | this.GetMatches(new RegExp('', 'gm'), 'comments');
32 |
33 | // Match attributes and their values
34 | // (:|\w+)\s*=\s*(".*?"|\'.*?\'|\w+)*
35 | regex = new RegExp('([:\\w-\.]+)\\s*=\\s*(".*?"|\'.*?\'|\\w+)*', 'gm'); // Thanks to Tomi Blinnikka of Yahoo! for fixing namespaces in attributes
36 | while ((match = regex.exec(this.code)) != null) {
37 | push(this.matches, new dp.sh.Match(match[1], match.index, 'attribute'));
38 |
39 | // if xml is invalid and attribute has no property value, ignore it
40 | if (match[2] != undefined) {
41 | push(this.matches, new dp.sh.Match(match[2], match.index + match[0].indexOf(match[2]), 'attribute-value'));
42 | }
43 | }
44 |
45 | // Match opening and closing tag brackets
46 | // *\?*(?!\!)|/*\?*>
47 | this.GetMatches(new RegExp('*\\?*(?!\\!)|/*\\?*>', 'gm'), 'tag');
48 |
49 | // Match tag names
50 | // *\?*\s*(\w+)
51 | regex = new RegExp('*\\?*\\s*([:\\w-\.]+)', 'gm');
52 | while ((match = regex.exec(this.code)) != null) {
53 | push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'tag-name'));
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/site/site.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Json-lib
5 | /images/json-lib.png
6 | http://json-lib.sourceforge.net/
7 |
8 |
9 |
10 |
12 |
14 |
15 |
16 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
41 |
42 | ${reports}
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/JSONTestSuite.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | import junit.framework.TestSuite;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class JSONTestSuite extends TestSuite {
26 | public static TestSuite suite() throws Exception {
27 | TestSuite suite = new TestSuite();
28 | suite.setName("json-lib");
29 |
30 | suite.addTest(org.kordamp.json.AllTests.suite());
31 | suite.addTest(org.kordamp.json.regexp.AllTests.suite());
32 | suite.addTest(org.kordamp.json.filters.AllTests.suite());
33 | suite.addTest(org.kordamp.json.processors.AllTests.suite());
34 | suite.addTest(org.kordamp.json.util.AllTests.suite());
35 | suite.addTest(org.kordamp.json.xml.AllTests.suite());
36 | suite.addTest(org.kordamp.json.test.AllTests.suite());
37 |
38 | return suite;
39 | }
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/PrefixerPropertyNameProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | /**
19 | *
20 | */
21 | package org.kordamp.json;
22 |
23 | import org.kordamp.json.processors.PropertyNameProcessor;
24 |
25 | public class PrefixerPropertyNameProcessor implements PropertyNameProcessor {
26 | private final String prefix;
27 |
28 | public PrefixerPropertyNameProcessor(String prefix) {
29 | this.prefix = prefix;
30 | }
31 |
32 | public String processPropertyName(Class beanClass, String name) {
33 | return prefix + name;
34 | }
35 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONArrayAsJSON.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class TestJSONArrayAsJSON extends AbstractJSONTest {
24 | public TestJSONArrayAsJSON(String name) {
25 | super(name);
26 | }
27 |
28 | public static void main(String[] args) {
29 | junit.textui.TestRunner.run(TestJSONArrayAsJSON.class);
30 | }
31 |
32 | protected int getIndent() {
33 | return 2;
34 | }
35 |
36 | protected int getIndentFactor() {
37 | return 2;
38 | }
39 |
40 | protected Object[] getIsArrayExpectations() {
41 | return new Object[]{Boolean.TRUE, new JSONArray()};
42 | }
43 |
44 | protected Object[] getToStringExpectations1() {
45 | return new Object[]{"[1,true,\"json\"]", JSONArray.fromObject("[1,true,'json']")};
46 | }
47 |
48 | protected Object[] getToStringExpectations2() {
49 | return new Object[]{"[\n" + " 1,\n" + " true,\n" + " \"json\"\n" + "]",
50 | JSONArray.fromObject("[1,true,'json']")};
51 | }
52 |
53 | protected Object[] getToStringExpectations3() {
54 | return new Object[]{" [\n" + " 1,\n" + " true,\n" + " \"json\"\n" + " ]",
55 | JSONArray.fromObject("[1,true,'json']")};
56 |
57 | }
58 |
59 | protected Object[] getWriteExpectations() {
60 | return new Object[]{"[1,true,\"json\"]", JSONArray.fromObject("[1,true,'json']")};
61 | }
62 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONArrayStaticBuilders_Array_DynaBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | import org.kordamp.ezmorph.bean.MorphDynaBean;
21 | import org.kordamp.ezmorph.bean.MorphDynaClass;
22 |
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | /**
27 | * @author Andres Almiray
28 | */
29 | public class TestJSONArrayStaticBuilders_Array_DynaBean extends
30 | AbstractJSONArrayStaticBuildersTestCase {
31 | public TestJSONArrayStaticBuilders_Array_DynaBean(String name) {
32 | super(name);
33 | }
34 |
35 | public static void main(String[] args) {
36 | junit.textui.TestRunner.run(TestJSONArrayStaticBuilders_Array_DynaBean.class);
37 | }
38 |
39 | protected Object getSource() {
40 | Map map = new HashMap();
41 | String[] props = getProperties();
42 | for (int i = 0; i < props.length; i++) {
43 | map.put(props[i], PropertyConstants.getPropertyClass(props[i]));
44 | }
45 | map.put("class", Class.class);
46 | map.put("pexcluded", String.class);
47 | MorphDynaClass dynaClass = new MorphDynaClass(map);
48 | MorphDynaBean dynaBean = null;
49 | try {
50 | dynaBean = (MorphDynaBean) dynaClass.newInstance();
51 | for (int i = 0; i < props.length; i++) {
52 | dynaBean.set(props[i], PropertyConstants.getPropertyValue(props[i]));
53 | }
54 | dynaBean.set("class", Object.class);
55 | dynaBean.set("pexcluded", "");
56 | } catch (Exception e) {
57 | throw new RuntimeException(e);
58 | }
59 |
60 | return new Object[]{dynaBean};
61 | }
62 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONArrayStaticBuilders_JSONString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class TestJSONArrayStaticBuilders_JSONString extends AbstractJSONArrayStaticBuildersTestCase {
24 | public TestJSONArrayStaticBuilders_JSONString(String name) {
25 | super(name);
26 | }
27 |
28 | public static void main(String[] args) {
29 | junit.textui.TestRunner.run(TestJSONArrayStaticBuilders_JSONString.class);
30 | }
31 |
32 | protected Object getSource() {
33 | return new JsonBean();
34 | }
35 |
36 | public static class JsonBean implements JSONString {
37 | public String toJSONString() {
38 | return "[{\"parray\":[1,2],\"plong\":9223372036854775807,\"pchar\":\"J\",\"pboolean\":true,\"pfloat\":3.4028234663852886E38,\"pbean\":{\"parray\":null,\"plong\":null,\"pchar\":null,\"pboolean\":null,\"pfloat\":null,\"pbean\":null,\"pshort\":null,\"pdouble\":null,\"pclass\":null,\"pstring\":null,\"pint\":null,\"plist\":null,\"pfunction\":null,\"pmap\":null,\"pbyte\":null},\"pshort\":32767,\"pdouble\":1.7976931348623157E308,\"pclass\":\"java.lang.Object\",\"pstring\":\"json\",\"pint\":2147483647,\"plist\":[\"a\",\"b\"],\"pfunction\":function(){ this; },\"pmap\":null,\"pbyte\":127,\"class\":\"java.lang.Object\",\"pexcluded\":\"\"}]";
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONArrayStaticBuilders_String.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class TestJSONArrayStaticBuilders_String extends AbstractJSONArrayStaticBuildersTestCase {
24 | public TestJSONArrayStaticBuilders_String(String name) {
25 | super(name);
26 | }
27 |
28 | public static void main(String[] args) {
29 | junit.textui.TestRunner.run(TestJSONArrayStaticBuilders_String.class);
30 | }
31 |
32 | protected Object getSource() {
33 | return "[{\"parray\":[1,2],\"plong\":9223372036854775807,\"pchar\":\"J\",\"pboolean\":true,\"pfloat\":3.4028234663852886E38,\"pbean\":{\"parray\":null,\"plong\":null,\"pchar\":null,\"pboolean\":null,\"pfloat\":null,\"pbean\":null,\"pshort\":null,\"pdouble\":null,\"pclass\":null,\"pstring\":null,\"pint\":null,\"plist\":null,\"pfunction\":null,\"pmap\":null,\"pbyte\":null},\"pshort\":32767,\"pdouble\":1.7976931348623157E308,\"pclass\":\"java.lang.Object\",\"pstring\":\"json\",\"pint\":2147483647,\"plist\":[\"a\",\"b\"],\"pfunction\":function(){ this; },\"pmap\":null,\"pbyte\":127,\"class\":\"java.lang.Object\",\"pexcluded\":\"\"}]";
34 | }
35 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONNullAsJSON.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class TestJSONNullAsJSON extends AbstractJSONTest {
24 | public TestJSONNullAsJSON(String name) {
25 | super(name);
26 | }
27 |
28 | public static void main(String[] args) {
29 | junit.textui.TestRunner.run(TestJSONNullAsJSON.class);
30 | }
31 |
32 | protected int getIndent() {
33 | return 2;
34 | }
35 |
36 | protected int getIndentFactor() {
37 | return 2;
38 | }
39 |
40 | protected Object[] getIsArrayExpectations() {
41 | return new Object[]{Boolean.FALSE, JSONNull.getInstance()};
42 | }
43 |
44 | protected Object[] getToStringExpectations1() {
45 | return new Object[]{"null", JSONNull.getInstance()};
46 | }
47 |
48 | protected Object[] getToStringExpectations2() {
49 | return new Object[]{"null", JSONNull.getInstance()};
50 | }
51 |
52 | protected Object[] getToStringExpectations3() {
53 | return new Object[]{" null", JSONNull.getInstance()};
54 | }
55 |
56 | protected Object[] getWriteExpectations() {
57 | return new Object[]{"null", JSONNull.getInstance()};
58 | }
59 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONObjectStaticBuilders_DynaBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | import org.kordamp.ezmorph.bean.MorphDynaBean;
21 | import org.kordamp.ezmorph.bean.MorphDynaClass;
22 |
23 | import java.util.HashMap;
24 | import java.util.Map;
25 |
26 | /**
27 | * @author Andres Almiray
28 | */
29 | public class TestJSONObjectStaticBuilders_DynaBean extends AbstractJSONObjectStaticBuildersTestCase {
30 | public TestJSONObjectStaticBuilders_DynaBean(String name) {
31 | super(name);
32 | }
33 |
34 | public static void main(String[] args) {
35 | junit.textui.TestRunner.run(TestJSONObjectStaticBuilders_DynaBean.class);
36 | }
37 |
38 | protected Object getSource() {
39 | Map map = new HashMap();
40 | String[] props = getProperties();
41 | for (int i = 0; i < props.length; i++) {
42 | map.put(props[i], PropertyConstants.getPropertyClass(props[i]));
43 | }
44 | map.put("class", Class.class);
45 | map.put("pexcluded", String.class);
46 | MorphDynaClass dynaClass = new MorphDynaClass(map);
47 | MorphDynaBean dynaBean = null;
48 | try {
49 | dynaBean = (MorphDynaBean) dynaClass.newInstance();
50 | for (int i = 0; i < props.length; i++) {
51 | dynaBean.set(props[i], PropertyConstants.getPropertyValue(props[i]));
52 | }
53 | dynaBean.set("class", Object.class);
54 | dynaBean.set("pexcluded", "");
55 | } catch (Exception e) {
56 | throw new RuntimeException(e);
57 | }
58 |
59 | return dynaBean;
60 | }
61 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONObjectStaticBuilders_JSONObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class TestJSONObjectStaticBuilders_JSONObject extends
24 | AbstractJSONObjectStaticBuildersTestCase {
25 | public TestJSONObjectStaticBuilders_JSONObject(String name) {
26 | super(name);
27 | }
28 |
29 | public static void main(String[] args) {
30 | junit.textui.TestRunner.run(TestJSONObjectStaticBuilders_JSONObject.class);
31 | }
32 |
33 | protected Object getSource() {
34 | String[] props = getProperties();
35 | JSONObject jsonObject = new JSONObject();
36 | try {
37 | for (int i = 0; i < props.length; i++) {
38 | jsonObject.element(props[i], PropertyConstants.getPropertyValue(props[i]));
39 | }
40 | jsonObject.element("class", Object.class);
41 | jsonObject.element("pexcluded", "");
42 | } catch (Exception e) {
43 | throw new RuntimeException(e);
44 | }
45 |
46 | return jsonObject;
47 | }
48 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONObjectStaticBuilders_JSONString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class TestJSONObjectStaticBuilders_JSONString extends
24 | AbstractJSONObjectStaticBuildersTestCase {
25 | public TestJSONObjectStaticBuilders_JSONString(String name) {
26 | super(name);
27 | }
28 |
29 | public static void main(String[] args) {
30 | junit.textui.TestRunner.run(TestJSONObjectStaticBuilders_JSONString.class);
31 | }
32 |
33 | protected Object getSource() {
34 | return new JsonBean();
35 | }
36 |
37 | public static class JsonBean implements JSONString {
38 |
39 | public String toJSONString() {
40 | return "{\"parray\":[1,2],\"plong\":9223372036854775807,\"pchar\":\"J\",\"pboolean\":true,\"pfloat\":3.4028234663852886E38,\"pbean\":{\"parray\":null,\"plong\":null,\"pchar\":null,\"pboolean\":null,\"pfloat\":null,\"pbean\":null,\"pshort\":null,\"pdouble\":null,\"pclass\":null,\"pstring\":null,\"pint\":null,\"plist\":null,\"pfunction\":null,\"pmap\":null,\"pbyte\":null},\"pshort\":32767,\"pdouble\":1.7976931348623157E308,\"pclass\":\"java.lang.Object\",\"pstring\":\"json\",\"pint\":2147483647,\"plist\":[\"a\",\"b\"],\"pfunction\":function(){ this; },\"pmap\":null,\"pbyte\":127,\"class\":\"java.lang.Object\",\"pexcluded\":\"\"}";
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONObjectStaticBuilders_JSONTokener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | import org.kordamp.json.util.JSONTokener;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class TestJSONObjectStaticBuilders_JSONTokener extends
26 | AbstractJSONObjectStaticBuildersTestCase {
27 | public TestJSONObjectStaticBuilders_JSONTokener(String name) {
28 | super(name);
29 | }
30 |
31 | public static void main(String[] args) {
32 | junit.textui.TestRunner.run(TestJSONObjectStaticBuilders_JSONTokener.class);
33 | }
34 |
35 | protected Object getSource() {
36 | return new JSONTokener(
37 | "{\"parray\":[1,2],\"plong\":9223372036854775807,\"pchar\":\"J\",\"pboolean\":true,\"pfloat\":3.4028234663852886E38,\"pbean\":{\"parray\":null,\"plong\":null,\"pchar\":null,\"pboolean\":null,\"pfloat\":null,\"pbean\":null,\"pshort\":null,\"pdouble\":null,\"pclass\":null,\"pstring\":null,\"pint\":null,\"plist\":null,\"pfunction\":null,\"pmap\":null,\"pbyte\":null},\"pshort\":32767,\"pdouble\":1.7976931348623157E308,\"pclass\":\"java.lang.Object\",\"pstring\":\"json\",\"pint\":2147483647,\"plist\":[\"a\",\"b\"],\"pfunction\":function(){ this; },\"pmap\":null,\"pbyte\":127,\"class\":\"java.lang.Object\",\"pexcluded\":\"\"}");
38 | }
39 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONObjectStaticBuilders_Map.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class TestJSONObjectStaticBuilders_Map extends AbstractJSONObjectStaticBuildersTestCase {
27 | public TestJSONObjectStaticBuilders_Map(String name) {
28 | super(name);
29 | }
30 |
31 | public static void main(String[] args) {
32 | junit.textui.TestRunner.run(TestJSONObjectStaticBuilders_Map.class);
33 | }
34 |
35 | protected Object getSource() {
36 | Map map = new HashMap();
37 | String[] props = getProperties();
38 | for (int i = 0; i < props.length; i++) {
39 | map.put(props[i], PropertyConstants.getPropertyValue(props[i]));
40 | }
41 | map.put("class", "");
42 | map.put("pexcluded", "");
43 | return map;
44 | }
45 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONObjectStaticBuilders_ObjectBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | import org.apache.commons.beanutils.PropertyUtils;
21 | import org.kordamp.json.sample.ObjectBean;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class TestJSONObjectStaticBuilders_ObjectBean extends
27 | AbstractJSONObjectStaticBuildersTestCase {
28 | public TestJSONObjectStaticBuilders_ObjectBean(String name) {
29 | super(name);
30 | }
31 |
32 | public static void main(String[] args) {
33 | junit.textui.TestRunner.run(TestJSONObjectStaticBuilders_ObjectBean.class);
34 | }
35 |
36 | protected Object getSource() {
37 | ObjectBean bean = new ObjectBean();
38 | String[] props = getProperties();
39 | try {
40 | for (int i = 0; i < props.length; i++) {
41 | PropertyUtils.setProperty(bean, props[i],
42 | PropertyConstants.getPropertyValue(props[i]));
43 | }
44 | } catch (Exception e) {
45 | throw new RuntimeException(e);
46 | }
47 | return bean;
48 | }
49 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONObjectStaticBuilders_PrimitiveBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | import org.apache.commons.beanutils.PropertyUtils;
21 | import org.kordamp.json.sample.PrimitiveBean;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class TestJSONObjectStaticBuilders_PrimitiveBean extends
27 | AbstractJSONObjectStaticBuildersTestCase {
28 | public TestJSONObjectStaticBuilders_PrimitiveBean(String name) {
29 | super(name);
30 | }
31 |
32 | public static void main(String[] args) {
33 | junit.textui.TestRunner.run(TestJSONObjectStaticBuilders_PrimitiveBean.class);
34 | }
35 |
36 | protected Object getSource() {
37 | PrimitiveBean bean = new PrimitiveBean();
38 | String[] props = getProperties();
39 | try {
40 | for (int i = 0; i < props.length; i++) {
41 | PropertyUtils.setProperty(bean, props[i],
42 | PropertyConstants.getPropertyValue(props[i]));
43 | }
44 | } catch (Exception e) {
45 | throw new RuntimeException(e);
46 | }
47 | return bean;
48 | }
49 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/TestJSONObjectStaticBuilders_String.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class TestJSONObjectStaticBuilders_String extends AbstractJSONObjectStaticBuildersTestCase {
24 | public TestJSONObjectStaticBuilders_String(String name) {
25 | super(name);
26 | }
27 |
28 | public static void main(String[] args) {
29 | junit.textui.TestRunner.run(TestJSONObjectStaticBuilders_String.class);
30 | }
31 |
32 | protected Object getSource() {
33 | return "{\"parray\":[1,2],\"plong\":9223372036854775807,\"pchar\":\"J\",\"pboolean\":true,\"pfloat\":3.4028234663852886E38,\"pbean\":{\"parray\":null,\"plong\":null,\"pchar\":null,\"pboolean\":null,\"pfloat\":null,\"pbean\":null,\"pshort\":null,\"pdouble\":null,\"pclass\":null,\"pstring\":null,\"pint\":null,\"plist\":null,\"pfunction\":null,\"pmap\":null,\"pbyte\":null},\"pshort\":32767,\"pdouble\":1.7976931348623157E308,\"pclass\":\"java.lang.Object\",\"pstring\":\"json\",\"pint\":2147483647,\"plist\":[\"a\",\"b\"],\"pfunction\":function(){ this; },\"pmap\":null,\"pbyte\":127,\"class\":\"java.lang.Object\",\"pexcluded\":\"\"}";
34 | }
35 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/bugs/FieldBindingTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.bugs;
19 |
20 | import junit.framework.TestCase;
21 | import org.kordamp.json.JSONObject;
22 | import org.kordamp.json.JsonConfig;
23 |
24 | /**
25 | * @author Kohsuke Kawaguchi
26 | */
27 | public class FieldBindingTest extends TestCase {
28 | public void test1() throws Exception {
29 | Foo f = new Foo();
30 | f.x = 5;
31 | f.y = "test";
32 | JsonConfig jsonConfig = new JsonConfig();
33 | jsonConfig.setIgnorePublicFields(false);
34 | JSONObject o = JSONObject.fromObject(f, jsonConfig);
35 | assertEquals(o.getInt("x"), 5);
36 | assertEquals(o.getString("y"), "test");
37 | assertEquals(o.size(), 2);
38 | }
39 |
40 | public void test2() throws Exception {
41 | // Property introspection is not capable of reading properties
42 | // from a private member class, even if they are defined as
43 | // public fields, thus the returned JSONObject must be empty
44 |
45 | Bar f = new Bar();
46 | f.x = 5;
47 | f.y = "test";
48 | JsonConfig jsonConfig = new JsonConfig();
49 | jsonConfig.setIgnorePublicFields(false);
50 | JSONObject o = JSONObject.fromObject(f, jsonConfig);
51 | assertTrue(o.isEmpty());
52 | // assertEquals(o.getInt("x"), 5);
53 | // assertEquals(o.getString("y"), "test");
54 | // assertEquals(o.size(), 2);
55 | }
56 |
57 | public final class Foo {
58 | public int x;
59 | public String y;
60 | }
61 |
62 | private final class Bar {
63 | public int x;
64 | public String y;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/bugs/TestBug2843623.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.bugs;
19 |
20 | import junit.framework.TestCase;
21 | import org.kordamp.json.JSONObject;
22 | import org.kordamp.json.JsonConfig;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | public class TestBug2843623 extends TestCase {
28 | public void testSample() {
29 | Container orig = new Container();
30 | List strings = new ArrayList();
31 | strings.add("one");
32 | strings.add("two");
33 | strings.add("three");
34 | orig.setMyList(strings);
35 |
36 | JSONObject jobj = JSONObject.fromObject(orig);
37 | Container root = new Container();
38 | Container res = (Container) JSONObject.toBean(jobj, root, new JsonConfig());
39 | assertTrue(res.getMyList().size() > 0);
40 | assertTrue(root.getMyList().size() > 0);
41 | }
42 |
43 | public static class Container {
44 | private List myList = new ArrayList();
45 |
46 | public List getMyList() {
47 | return myList;
48 | }
49 |
50 | public void setMyList(List strings) {
51 | this.myList.addAll(strings);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/filters/AllTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.filters;
19 |
20 | import junit.framework.TestSuite;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class AllTests extends TestSuite {
26 | public static TestSuite suite() throws Exception {
27 | TestSuite suite = new TestSuite();
28 | suite.setName("filters");
29 |
30 | suite.addTest(new TestSuite(TestAndPropertyFilter.class));
31 | suite.addTest(new TestSuite(TestCompositePropertyFilter.class));
32 | suite.addTest(new TestSuite(TestNotPropertyFilter.class));
33 | suite.addTest(new TestSuite(TestOrPropertyFilter.class));
34 | suite.addTest(new TestSuite(TestMappingPropertyFilter.class));
35 |
36 | return suite;
37 | }
38 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/filters/TestNotPropertyFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.filters;
19 |
20 | import junit.framework.TestCase;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class TestNotPropertyFilter extends TestCase {
26 | public TestNotPropertyFilter(String testName) {
27 | super(testName);
28 | }
29 |
30 | public static void main(String[] args) {
31 | junit.textui.TestRunner.run(TestNotPropertyFilter.class);
32 | }
33 |
34 | public void testApply_true() {
35 | NotPropertyFilter filter = new NotPropertyFilter(new TruePropertyFilter());
36 | assertFalse(filter.apply(null, null, null));
37 | }
38 |
39 | public void testApply_false() {
40 | NotPropertyFilter filter = new NotPropertyFilter(new FalsePropertyFilter());
41 | assertTrue(filter.apply(null, null, null));
42 | }
43 |
44 | public void testApply_null() {
45 | NotPropertyFilter filter = new NotPropertyFilter(null);
46 | assertFalse(filter.apply(null, null, null));
47 | }
48 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/processors/AllTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import junit.framework.TestSuite;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class AllTests extends TestSuite {
26 | public static TestSuite suite() throws Exception {
27 | TestSuite suite = new TestSuite();
28 | suite.setName("processors");
29 |
30 | suite.addTest(new TestSuite(TestJsDateJsonBeanProcessor.class));
31 | suite.addTest(new TestSuite(TestJsDateJsonValueProcessor.class));
32 | suite.addTest(new TestSuite(TestJsonBeanProcessorMatcher.class));
33 | suite.addTest(new TestSuite(TestJsonVerifier.class));
34 | suite.addTest(new TestSuite(TestDefaultJsonValueProcessorMatcher.class));
35 | suite.addTest(new TestSuite(TestDefaultValueProcessorMatcher.class));
36 | suite.addTest(new TestSuite(TestDefaultPropertyNameProcessorMatcher.class));
37 |
38 | return suite;
39 | }
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/processors/StartsWithJsonBeanProcessorMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import java.util.Iterator;
21 | import java.util.Set;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class StartsWithJsonBeanProcessorMatcher extends JsonBeanProcessorMatcher {
27 | private String pattern;
28 |
29 | public StartsWithJsonBeanProcessorMatcher(String pattern) {
30 | this.pattern = pattern;
31 | }
32 |
33 | public Object getMatch(Class target, Set set) {
34 | if (target != null && set != null && target.getName()
35 | .startsWith(pattern)) {
36 | for (Iterator i = set.iterator(); i.hasNext(); ) {
37 | Class c = (Class) i.next();
38 | if (c.getName()
39 | .startsWith(pattern)) {
40 | return c;
41 | }
42 | }
43 | }
44 |
45 | return null;
46 | }
47 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/processors/TestDefaultJsonBeanProcessorMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import junit.framework.TestCase;
21 |
22 | import java.util.HashSet;
23 | import java.util.Set;
24 |
25 | /**
26 | * @author Andres Almiray
27 | */
28 | public class TestDefaultJsonBeanProcessorMatcher extends TestCase {
29 | public void testDefault() {
30 | JsonBeanProcessorMatcher matcher = JsonBeanProcessorMatcher.DEFAULT;
31 |
32 | assertNull(matcher.getMatch(null, null));
33 | assertNull(matcher.getMatch(Long.class, null));
34 | assertNull(matcher.getMatch(null, new HashSet()));
35 | assertNull(matcher.getMatch(Long.class, new HashSet()));
36 | Set set = new HashSet();
37 | set.add(Long.class);
38 | assertNotNull(matcher.getMatch(Long.class, set));
39 | assertEquals(Long.class, matcher.getMatch(Long.class, set));
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/processors/TestDefaultJsonValueProcessorMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import junit.framework.TestCase;
21 |
22 | import java.util.HashSet;
23 | import java.util.Set;
24 |
25 | /**
26 | * @author Andres Almiray
27 | */
28 | public class TestDefaultJsonValueProcessorMatcher extends TestCase {
29 | public void testDefault() {
30 | JsonValueProcessorMatcher matcher = JsonValueProcessorMatcher.DEFAULT;
31 |
32 | assertNull(matcher.getMatch(null, null));
33 | assertNull(matcher.getMatch(Long.class, null));
34 | assertNull(matcher.getMatch(null, new HashSet()));
35 | assertNull(matcher.getMatch(Long.class, new HashSet()));
36 | Set set = new HashSet();
37 | set.add(Long.class);
38 | assertNotNull(matcher.getMatch(Long.class, set));
39 | assertEquals(Long.class, matcher.getMatch(Long.class, set));
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/processors/TestDefaultPropertyNameProcessorMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import junit.framework.TestCase;
21 |
22 | import java.util.HashSet;
23 | import java.util.Set;
24 |
25 | /**
26 | * @author Andres Almiray
27 | */
28 | public class TestDefaultPropertyNameProcessorMatcher extends TestCase {
29 | public void testDefault() {
30 | PropertyNameProcessorMatcher matcher = PropertyNameProcessorMatcher.DEFAULT;
31 |
32 | assertNull(matcher.getMatch(null, null));
33 | assertNull(matcher.getMatch(Long.class, null));
34 | assertNull(matcher.getMatch(null, new HashSet()));
35 | assertNull(matcher.getMatch(Long.class, new HashSet()));
36 | Set set = new HashSet();
37 | set.add(Long.class);
38 | assertNotNull(matcher.getMatch(Long.class, set));
39 | assertEquals(Long.class, matcher.getMatch(Long.class, set));
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/processors/TestJsonBeanProcessorMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.processors;
19 |
20 | import junit.framework.TestCase;
21 |
22 | import java.util.HashSet;
23 | import java.util.Set;
24 |
25 | /**
26 | * @author Andres Almiray
27 | */
28 | public class TestJsonBeanProcessorMatcher extends TestCase {
29 | public static void main(String[] args) {
30 | junit.textui.TestRunner.run(TestJsonBeanProcessorMatcher.class);
31 | }
32 |
33 | public void testGetMatchUsingStartsWith() {
34 | Set set = new HashSet();
35 | set.add(JsonBeanProcessorMatcher.class);
36 | set.add(JsonBeanProcessorMatcher.DEFAULT.getClass());
37 |
38 | JsonBeanProcessorMatcher matcher = new StartsWithJsonBeanProcessorMatcher(
39 | "org.kordamp.json.processors.JsonBeanProcessorMatcher$");
40 | assertEquals(JsonBeanProcessorMatcher.DEFAULT.getClass(), matcher.getMatch(
41 | JsonBeanProcessorMatcher.DEFAULT.getClass(), set));
42 | }
43 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/regexp/AbstractRegexpMatcherTestCase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.regexp;
19 |
20 | import junit.framework.TestCase;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public abstract class AbstractRegexpMatcherTestCase extends TestCase {
26 | public AbstractRegexpMatcherTestCase(String name) {
27 | super(name);
28 | }
29 |
30 | public void testGetGroupIfMatches() {
31 | RegexpMatcher regexpMatcher = getRegexpMatcher("[a-z]*([0-9]+)[a-z]*");
32 | assertEquals("123", regexpMatcher.getGroupIfMatches("abc123edf", 1));
33 | assertEquals("", regexpMatcher.getGroupIfMatches("abcedf", 1));
34 | }
35 |
36 | public void testMatches() {
37 | assertTrue(getRegexpMatcher(".*").matches("everything"));
38 | assertTrue(getRegexpMatcher("^json$").matches("json"));
39 | assertFalse(getRegexpMatcher("^json$").matches("json "));
40 | }
41 |
42 | protected abstract RegexpMatcher getRegexpMatcher(String pattern);
43 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/regexp/AllTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.regexp;
19 |
20 | import junit.framework.TestSuite;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class AllTests extends TestSuite {
26 | public static TestSuite suite() throws Exception {
27 | TestSuite suite = new TestSuite();
28 | suite.setName("regexp");
29 |
30 | suite.addTest(new TestSuite(TestJdkRegexpMatcher.class));
31 |
32 | return suite;
33 | }
34 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/regexp/TestJdkRegexpMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.regexp;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class TestJdkRegexpMatcher extends AbstractRegexpMatcherTestCase {
24 | public TestJdkRegexpMatcher(String name) {
25 | super(name);
26 | }
27 |
28 | public static void main(String[] args) {
29 | junit.textui.TestRunner.run(TestJdkRegexpMatcher.class);
30 | }
31 |
32 | protected RegexpMatcher getRegexpMatcher(String pattern) {
33 | return new JdkRegexpMatcher(pattern);
34 | }
35 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/AnnotatedBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class AnnotatedBean {
24 | private String string1;
25 | @JsonAnnotation
26 | private String string2;
27 | private String string3;
28 |
29 | public String getString1() {
30 | return string1;
31 | }
32 |
33 | public void setString1(String string) {
34 | this.string1 = string;
35 | }
36 |
37 | public String getString2() {
38 | return string2;
39 | }
40 |
41 | public void setString2(String string) {
42 | this.string2 = string;
43 | }
44 |
45 | @JsonAnnotation
46 | public String getString3() {
47 | return string3;
48 | }
49 |
50 | public void setString3(String string) {
51 | this.string3 = string;
52 | }
53 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/AnnotationBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | @JsonAnnotation("json")
24 | public class AnnotationBean {
25 | private String string;
26 |
27 | public String getString() {
28 | return string;
29 | }
30 |
31 | public void setString(String string) {
32 | this.string = string;
33 | }
34 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/ArrayBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class ArrayBean {
27 | private BeanA[] beans;
28 |
29 | public BeanA[] getBeans() {
30 | return beans;
31 | }
32 |
33 | public void setBeans(BeanA[] beans) {
34 | this.beans = beans;
35 | }
36 |
37 | public String toString() {
38 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
39 | }
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/ArrayJSONStringBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.ArrayUtils;
21 | import org.kordamp.json.JSONString;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class ArrayJSONStringBean implements JSONString {
27 | private String value;
28 |
29 | public String getValue() {
30 | return value;
31 | }
32 |
33 | public void setValue(String value) {
34 | this.value = value;
35 | }
36 |
37 | public String toJSONString() {
38 | return ArrayUtils.toString(value.split(","))
39 | .replace('{', '[')
40 | .replace('}', ']');
41 | }
42 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/BeanA1763699.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class BeanA1763699 {
27 | private BeanB1763699[] bbeans;
28 |
29 | public BeanB1763699[] getBbeans() {
30 | return bbeans;
31 | }
32 |
33 | public void setBbeans(BeanB1763699[] bbeans) {
34 | this.bbeans = bbeans;
35 | }
36 |
37 | public String toString() {
38 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
39 | }
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/BeanB.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class BeanB extends BeanA {
27 | private int[] intarray = new int[]{1, 2, 3};
28 |
29 | public int[] getIntarray() {
30 | return intarray;
31 | }
32 |
33 | public void setIntarray(int[] intarray) {
34 | this.intarray = intarray;
35 | }
36 |
37 | public String toString() {
38 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
39 | }
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/BeanB1763699.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class BeanB1763699 {
27 | private String str;
28 |
29 | public String getStr() {
30 | return str;
31 | }
32 |
33 | public void setStr(String str) {
34 | this.str = str;
35 | }
36 |
37 | public String toString() {
38 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
39 | }
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/BeanC.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class BeanC {
27 | private BeanA beanA = new BeanA();
28 | private BeanB beanB = new BeanB();
29 |
30 | public BeanA getBeanA() {
31 | return beanA;
32 | }
33 |
34 | public void setBeanA(BeanA beanA) {
35 | this.beanA = beanA;
36 | }
37 |
38 | public BeanB getBeanB() {
39 | return beanB;
40 | }
41 |
42 | public void setBeanB(BeanB beanB) {
43 | this.beanB = beanB;
44 | }
45 |
46 | public String toString() {
47 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
48 | }
49 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/BeanFoo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class BeanFoo {
24 | private String[][] items;
25 |
26 | public String[][] getItems() {
27 | return items;
28 | }
29 |
30 | public void setItems(String[][] items) {
31 | this.items = items;
32 | }
33 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/BeanWithFunc.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.kordamp.json.JSONFunction;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class BeanWithFunc {
26 | private JSONFunction function;
27 |
28 | public BeanWithFunc(JSONFunction function) {
29 | this.function = function;
30 | }
31 |
32 | public BeanWithFunc(String function) {
33 | this.function = new JSONFunction(function);
34 | }
35 |
36 | public JSONFunction getFunction() {
37 | return function;
38 | }
39 |
40 | public void setFunction(JSONFunction function) {
41 | this.function = function;
42 | }
43 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/ChildBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class ChildBean extends ValueBean {
24 | private ParentBean parent;
25 |
26 | public ParentBean getParent() {
27 | return parent;
28 | }
29 |
30 | public void setParent(ParentBean parent) {
31 | this.parent = parent;
32 | }
33 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/ClassBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class ClassBean {
24 | private Class klass;
25 |
26 | public Class getKlass() {
27 | return klass;
28 | }
29 |
30 | public void setKlass(Class klass) {
31 | this.klass = klass;
32 | }
33 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/DateBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import java.util.Date;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class DateBean extends ValueBean {
26 | private Date date;
27 |
28 | public Date getDate() {
29 | return date;
30 | }
31 |
32 | public void setDate(Date date) {
33 | this.date = date;
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | final StringBuilder sb = new StringBuilder("DateBean{");
39 | sb.append("date=").append(date);
40 | sb.append('}');
41 | return sb.toString();
42 | }
43 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/EnumBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import java.util.HashSet;
21 | import java.util.Set;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class EnumBean {
27 | private JsonEnum jsonEnum;
28 | private String string;
29 | private Set enums = new HashSet();
30 |
31 | public JsonEnum getJsonEnum() {
32 | return jsonEnum;
33 | }
34 |
35 | public void setJsonEnum(JsonEnum jsonEnum) {
36 | this.jsonEnum = jsonEnum;
37 | }
38 |
39 | public String getString() {
40 | return string;
41 | }
42 |
43 | public void setString(String string) {
44 | this.string = string;
45 | }
46 |
47 | public Set getEnums() {
48 | return enums;
49 | }
50 |
51 | public void setEnums(Set enums) {
52 | this.enums = enums;
53 | }
54 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/FieldBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class FieldBean {
27 | public String string;
28 | private int value;
29 |
30 | public int getValue() {
31 | return value;
32 | }
33 |
34 | public void setValue(int value) {
35 | this.value = value;
36 | }
37 |
38 | public String toString() {
39 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
40 | }
41 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/IdentityJsonValueProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.kordamp.json.JsonConfig;
21 | import org.kordamp.json.processors.JsonValueProcessor;
22 | import org.kordamp.json.util.JSONUtils;
23 |
24 | /**
25 | * @author Andres Almiray
26 | */
27 | public class IdentityJsonValueProcessor implements JsonValueProcessor {
28 | public Object processArrayValue(Object value, JsonConfig jsonConfig) {
29 | return process(value, jsonConfig);
30 | }
31 |
32 | public Object processObjectValue(String key, Object value, JsonConfig jsonConfig) {
33 | return process(value, jsonConfig);
34 | }
35 |
36 | private Object process(Object value, JsonConfig jsonConfig) {
37 | if (JSONUtils.isNumber(value)) {
38 | value = JSONUtils.transformNumber((Number) value);
39 | }
40 | return value;
41 | }
42 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/InterfaceBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class InterfaceBean {
24 | private Runnable runnable;
25 |
26 | public Runnable getRunnable() {
27 | return runnable;
28 | }
29 |
30 | public void setRunnable(Runnable runnable) {
31 | this.runnable = runnable;
32 | }
33 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/JSONTestBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | public class JSONTestBean {
24 | private String email = "";
25 | private String inventoryID = "";
26 | private String notes = "";
27 | private Map options = new HashMap();
28 | private String rateID = "";
29 |
30 | public String getEmail() {
31 | return email;
32 | }
33 |
34 | public void setEmail(String email) {
35 | this.email = email;
36 | }
37 |
38 | public String getInventoryID() {
39 | return inventoryID;
40 | }
41 |
42 | public void setInventoryID(String inventoryID) {
43 | this.inventoryID = inventoryID;
44 | }
45 |
46 | public String getNotes() {
47 | return notes;
48 | }
49 |
50 | public void setNotes(String notes) {
51 | this.notes = notes;
52 | }
53 |
54 | public Map getOptions() {
55 | return options;
56 | }
57 |
58 | public void setOptions(Map options) {
59 | this.options = options;
60 | }
61 |
62 | public String getRateID() {
63 | return rateID;
64 | }
65 |
66 | public void setRateID(String rateID) {
67 | this.rateID = rateID;
68 | }
69 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/JavaIdentifierBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class JavaIdentifierBean {
24 | private String camelCase;
25 | private String under_score;
26 | private String whitespace;
27 |
28 | public String getCamelCase() {
29 | return camelCase;
30 | }
31 |
32 | public void setCamelCase(String camelCase) {
33 | this.camelCase = camelCase;
34 | }
35 |
36 | public String getUnder_score() {
37 | return under_score;
38 | }
39 |
40 | public void setUnder_score(String under_score) {
41 | this.under_score = under_score;
42 | }
43 |
44 | public String getWhitespace() {
45 | return whitespace;
46 | }
47 |
48 | public void setWhitespace(String whitespace) {
49 | this.whitespace = whitespace;
50 | }
51 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/JsonAnnotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | @Retention(RetentionPolicy.RUNTIME)
27 | public @interface JsonAnnotation {
28 | String value() default "";
29 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/JsonEnum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public enum JsonEnum {
24 | ARRAY,
25 | OBJECT
26 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/ListingBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class ListingBean {
27 | private List attributes = new ArrayList();
28 |
29 | public void addAttribute(Object value) {
30 | this.attributes.add(value);
31 | }
32 |
33 | public List getAttributes() {
34 | return attributes;
35 | }
36 |
37 | public void setAttributes(List attributes) {
38 | this.attributes = attributes;
39 | }
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/MappedBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import java.util.HashMap;
21 | import java.util.List;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class MappedBean extends HashMap {
27 | private static final long serialVersionUID = -3372716996620968313L;
28 |
29 | public List getList() {
30 | return (List) get("list");
31 | }
32 |
33 | public void setList(List list) {
34 | put("list", list);
35 | }
36 |
37 | public String getName() {
38 | return (String) get("name");
39 | }
40 |
41 | public void setName(String name) {
42 | put("name", name);
43 | }
44 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/MappingBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import java.util.HashMap;
21 | import java.util.Map;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class MappingBean {
27 | private Map attributes = new HashMap();
28 |
29 | public void addAttribute(Object key, Object value) {
30 | this.attributes.put(key, value);
31 | }
32 |
33 | public Map getAttributes() {
34 | return attributes;
35 | }
36 |
37 | public void setAttributes(Map attributes) {
38 | this.attributes = attributes;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/Media.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class Media {
27 | private String title;
28 |
29 | public String getTitle() {
30 | return title;
31 | }
32 |
33 | public void setTitle(String title) {
34 | this.title = title;
35 | }
36 |
37 | public String toString() {
38 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
39 | }
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/MediaBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class MediaBean {
27 | private String title;
28 |
29 | public String getTitle() {
30 | return title;
31 | }
32 |
33 | public void setTitle(String title) {
34 | this.title = title;
35 | }
36 |
37 | public String toString() {
38 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
39 | }
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/MediaList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | import java.util.ArrayList;
24 |
25 | /**
26 | * @author Andres Almiray
27 | */
28 | public class MediaList {
29 | private ArrayList media;
30 |
31 | public ArrayList getMedia() {
32 | return media;
33 | }
34 |
35 | public void setMedia(ArrayList media) {
36 | this.media = media;
37 | }
38 |
39 | public String toString() {
40 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
41 | }
42 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/MediaListBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | import java.util.List;
24 |
25 | /**
26 | * @author Andres Almiray
27 | */
28 | public class MediaListBean {
29 | private Object media;
30 | private List media2;
31 |
32 | public Object getMedia() {
33 | return media;
34 | }
35 |
36 | public void setMedia(Object media) {
37 | this.media = media;
38 | }
39 |
40 | public List getMedia2() {
41 | return media2;
42 | }
43 |
44 | public void setMedia2(List media2) {
45 | this.media2 = media2;
46 | }
47 |
48 | public String toString() {
49 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
50 | }
51 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/NumberArrayBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class NumberArrayBean {
27 | private byte[] bytes;
28 | private double[] doubles;
29 | private float[] floats;
30 | private int[] ints;
31 | private long[] longs;
32 | private short[] shorts;
33 |
34 | public byte[] getBytes() {
35 | return bytes;
36 | }
37 |
38 | public void setBytes(byte[] bytes) {
39 | this.bytes = bytes;
40 | }
41 |
42 | public double[] getDoubles() {
43 | return doubles;
44 | }
45 |
46 | public void setDoubles(double[] doubles) {
47 | this.doubles = doubles;
48 | }
49 |
50 | public float[] getFloats() {
51 | return floats;
52 | }
53 |
54 | public void setFloats(float[] floats) {
55 | this.floats = floats;
56 | }
57 |
58 | public int[] getInts() {
59 | return ints;
60 | }
61 |
62 | public void setInts(int[] ints) {
63 | this.ints = ints;
64 | }
65 |
66 | public long[] getLongs() {
67 | return longs;
68 | }
69 |
70 | public void setLongs(long[] longs) {
71 | this.longs = longs;
72 | }
73 |
74 | public short[] getShorts() {
75 | return shorts;
76 | }
77 |
78 | public void setShorts(short[] shorts) {
79 | this.shorts = shorts;
80 | }
81 |
82 | public String toString() {
83 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
84 | }
85 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/ObjectJSONStringBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.kordamp.json.JSONString;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class ObjectJSONStringBean implements JSONString {
26 | private int id;
27 | private String name;
28 |
29 | public int getId() {
30 | return id;
31 | }
32 |
33 | public void setId(int id) {
34 | this.id = id;
35 | }
36 |
37 | public String getName() {
38 | return name;
39 | }
40 |
41 | public void setName(String name) {
42 | this.name = name;
43 | }
44 |
45 | public String toJSONString() {
46 | return new StringBuffer().append("{")
47 | .append("\"name\":\"")
48 | .append((name == null) ? "" : name)
49 | .append("\"}")
50 | .toString();
51 | }
52 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/PackageProtectedBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class PackageProtectedBean {
27 | private int value;
28 |
29 | PackageProtectedBean() {
30 | }
31 |
32 | public int getValue() {
33 | return value;
34 | }
35 |
36 | public void setValue(int value) {
37 | this.value = value;
38 | }
39 |
40 | public String toString() {
41 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
42 | }
43 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/ParentBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class ParentBean extends ValueBean {
24 | private ChildBean child;
25 |
26 | public ChildBean getChild() {
27 | return child;
28 | }
29 |
30 | public void setChild(ChildBean child) {
31 | this.child = child;
32 | child.setParent(this);
33 | }
34 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/Player.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class Player {
27 | private MediaList mediaList;
28 |
29 | public MediaList getMediaList() {
30 | return mediaList;
31 | }
32 |
33 | public void setMediaList(MediaList mediaList) {
34 | this.mediaList = mediaList;
35 | }
36 |
37 | public String toString() {
38 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
39 | }
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/PlayerList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | import java.util.ArrayList;
24 |
25 | /**
26 | * @author Andres Almiray
27 | */
28 | public class PlayerList {
29 | private ArrayList player;
30 |
31 | public ArrayList getPlayer() {
32 | return player;
33 | }
34 |
35 | public void setPlayer(ArrayList player) {
36 | this.player = player;
37 | }
38 |
39 | public String toString() {
40 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
41 | }
42 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/PrivateConstructorBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.ToStringBuilder;
21 | import org.apache.commons.lang3.builder.ToStringStyle;
22 |
23 | /**
24 | * @author Andres Almiray
25 | */
26 | public class PrivateConstructorBean {
27 | private int value;
28 |
29 | private PrivateConstructorBean() {
30 | }
31 |
32 | public int getValue() {
33 | return value;
34 | }
35 |
36 | public void setValue(int value) {
37 | this.value = value;
38 | }
39 |
40 | public String toString() {
41 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
42 | }
43 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/PropertyBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class PropertyBean {
24 | private final String propertyWithNoWriteMethod = "json";
25 | private String propertyWithNoReadMethod;
26 |
27 | public String getPropertyWithNoWriteMethod() {
28 | return propertyWithNoWriteMethod;
29 | }
30 |
31 | public void setPropertyWithNoReadMethod(String propertyWithNoReadMethod) {
32 | this.propertyWithNoReadMethod = propertyWithNoReadMethod;
33 | }
34 |
35 | public String valueOfPropertyWithNoReadMethod() {
36 | return propertyWithNoReadMethod;
37 | }
38 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/SetBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.EqualsBuilder;
21 | import org.apache.commons.lang3.builder.HashCodeBuilder;
22 | import org.apache.commons.lang3.builder.ToStringBuilder;
23 | import org.apache.commons.lang3.builder.ToStringStyle;
24 |
25 | import java.util.HashSet;
26 | import java.util.Set;
27 |
28 | /**
29 | * @author Andres Almiray
30 | */
31 | public class SetBean {
32 | private Set attributes = new HashSet();
33 |
34 | public void addAttribute(Object value) {
35 | this.attributes.add(value);
36 | }
37 |
38 | public Set getAttributes() {
39 | return attributes;
40 | }
41 |
42 | public void setAttributes(Set attributes) {
43 | this.attributes = attributes;
44 | }
45 |
46 | public int hashCode() {
47 | return HashCodeBuilder.reflectionHashCode(this);
48 | }
49 |
50 | public boolean equals(Object obj) {
51 | if (obj == this) {
52 | return true;
53 | }
54 | if (obj == null) {
55 | return false;
56 | }
57 | if (!SetBean.class.isAssignableFrom(obj.getClass())) {
58 | return false;
59 | }
60 | return EqualsBuilder.reflectionEquals(this, obj);
61 | }
62 |
63 | public String toString() {
64 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
65 | }
66 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/TransientBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | /**
21 | * @author Andres Almiray
22 | */
23 | public class TransientBean extends ValueBean {
24 | private transient int transientValue;
25 |
26 | public int getTransientValue() {
27 | return transientValue;
28 | }
29 |
30 | public void setTransientValue(int transientValue) {
31 | this.transientValue = transientValue;
32 | }
33 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/UnstandardBeanInstanceStrategy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.kordamp.json.JSONObject;
21 | import org.kordamp.json.util.NewBeanInstanceStrategy;
22 |
23 | import java.lang.reflect.InvocationTargetException;
24 |
25 | /**
26 | * @author Andres Almiray
27 | */
28 | public class UnstandardBeanInstanceStrategy extends NewBeanInstanceStrategy {
29 | public Object newInstance(Class target, JSONObject source) throws InstantiationException,
30 | IllegalAccessException, SecurityException, NoSuchMethodException,
31 | InvocationTargetException {
32 | return new UnstandardBean(source.getInt("id"));
33 | }
34 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/sample/ValueBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.sample;
19 |
20 | import org.apache.commons.lang3.builder.EqualsBuilder;
21 | import org.apache.commons.lang3.builder.HashCodeBuilder;
22 | import org.apache.commons.lang3.builder.ToStringBuilder;
23 | import org.apache.commons.lang3.builder.ToStringStyle;
24 |
25 | /**
26 | * @author Andres Almiray
27 | */
28 | public class ValueBean {
29 | private int value;
30 |
31 | public int getValue() {
32 | return value;
33 | }
34 |
35 | public void setValue(int value) {
36 | this.value = value;
37 | }
38 |
39 | public int hashCode() {
40 | return HashCodeBuilder.reflectionHashCode(this);
41 | }
42 |
43 | public boolean equals(Object obj) {
44 | if (obj == this) {
45 | return true;
46 | }
47 | if (obj == null) {
48 | return false;
49 | }
50 | if (!ValueBean.class.isAssignableFrom(obj.getClass())) {
51 | return false;
52 | }
53 | return EqualsBuilder.reflectionEquals(this, obj);
54 | }
55 |
56 | public String toString() {
57 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
58 | }
59 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/test/AllTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.test;
19 |
20 | import junit.framework.TestSuite;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class AllTests extends TestSuite {
26 | public static TestSuite suite() throws Exception {
27 | TestSuite suite = new TestSuite();
28 | suite.setName("test");
29 |
30 | suite.addTest(new TestSuite(TestJSONAssert.class));
31 |
32 | return suite;
33 | }
34 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/util/AllTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.util;
19 |
20 | import junit.framework.TestSuite;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class AllTests extends TestSuite {
26 | public static TestSuite suite() throws Exception {
27 | TestSuite suite = new TestSuite();
28 | suite.setName("util");
29 |
30 | suite.addTest(new TestSuite(TestJavaIdentifierTransformer.class));
31 | suite.addTest(new TestSuite(TestJSONUtils.class));
32 | suite.addTest(new TestSuite(TestJSONTokener.class));
33 | suite.addTest(new TestSuite(TestJSONBuilder.class));
34 | suite.addTest(new TestSuite(TestJSONStringer.class));
35 | suite.addTest(new TestSuite(TestWebUtils.class));
36 | suite.addTest(new TestSuite(TestDefaultPropertyExclusionClassMatcher.class));
37 |
38 | return suite;
39 | }
40 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/util/TestDefaultPropertyExclusionClassMatcher.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.util;
19 |
20 | import junit.framework.TestCase;
21 |
22 | import java.util.HashSet;
23 | import java.util.Set;
24 |
25 | /**
26 | * @author Andres Almiray
27 | */
28 | public class TestDefaultPropertyExclusionClassMatcher extends TestCase {
29 | public void testDefault() {
30 | PropertyExclusionClassMatcher matcher = PropertyExclusionClassMatcher.DEFAULT;
31 |
32 | assertNull(matcher.getMatch(null, null));
33 | assertNull(matcher.getMatch(Long.class, null));
34 | assertNull(matcher.getMatch(null, new HashSet()));
35 | assertNull(matcher.getMatch(Long.class, new HashSet()));
36 | Set set = new HashSet();
37 | set.add(Long.class);
38 | assertNotNull(matcher.getMatch(Long.class, set));
39 | assertEquals(Long.class, matcher.getMatch(Long.class, set));
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/xml/AllTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.xml;
19 |
20 | import junit.framework.TestSuite;
21 |
22 | /**
23 | * @author Andres Almiray
24 | */
25 | public class AllTests extends TestSuite {
26 | public static TestSuite suite() throws Exception {
27 | TestSuite suite = new TestSuite();
28 | suite.setName("xml");
29 |
30 | suite.addTest(new TestSuite(TestXMLSerializer_reads.class));
31 | suite.addTest(new TestSuite(TestXMLSerializer_writes.class));
32 | suite.addTest(new TestSuite(TestUserSubmitted.class));
33 | suite.addTest(new TestSuite(TestAttributeWithNamespace.class));
34 | suite.addTest(new TestSuite(TestArrayAutoExpansion.class));
35 | suite.addTest(new TestSuite(TestXMLSerializer_writes_with_autoexpansion.class));
36 | suite.addTest(new TestSuite(TestXmlContainingTypeAttribute.class));
37 | suite.addTest(new TestSuite(TestXmlContainingCData.class));
38 | suite.addTest(new TestSuite(TestArrayAutoExpansion.class));
39 | suite.addTest(new TestSuite(TestXmlWithEntity.class));
40 | suite.addTest(new TestSuite(TestIdmlParsing.class));
41 | suite.addTest(new TestSuite(TestElementShouldNotBeArray.class));
42 | suite.addTest(new TestSuite(TestForcedArrayElementFlag.class));
43 |
44 | return suite;
45 | }
46 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/xml/TestAttributeWithNamespace.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.xml;
19 |
20 | import junit.framework.TestCase;
21 | import org.kordamp.json.JSONObject;
22 | import org.kordamp.json.test.JSONAssert;
23 |
24 |
25 | /**
26 | * @author Tobias Sodergren
27 | */
28 | public class TestAttributeWithNamespace extends TestCase {
29 |
30 | public TestAttributeWithNamespace(String name) {
31 | super(name);
32 | }
33 |
34 | public static void main(String[] args) {
35 | junit.textui.TestRunner.run(TestAttributeWithNamespace.class);
36 | }
37 |
38 | public void testShouldCreateCorrectJson() throws Exception {
39 |
40 | XMLSerializer reader = new XMLSerializer();
41 |
42 | JSONObject actual = (JSONObject) reader.read("" +
43 | "" +
44 | "" +
45 | "" +
46 | "");
47 |
48 | JSONObject expected = new JSONObject()
49 | .element("@DOMVersion", "8.0")
50 | .element("@Self", "d")
51 | .element("x:xmpmeta",
52 | new JSONObject()
53 | .element("@xmlns:x", "adobe:ns:meta/")
54 | .element("@x:xmptk", "Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27"));
55 |
56 | JSONAssert.assertEquals(expected, actual);
57 | }
58 | }
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/xml/TestElementShouldNotBeArray.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.xml;
19 |
20 | import junit.framework.TestCase;
21 | import org.kordamp.json.JSONObject;
22 |
23 | public class TestElementShouldNotBeArray extends TestCase {
24 |
25 | public void test_element_should_not_be_mistaken_as_array() {
26 | final XMLSerializer xmlSerializer = new XMLSerializer();
27 | xmlSerializer.setKeepCData(true);
28 | JSONObject actual = (JSONObject) xmlSerializer.read("\n" +
29 | "" +
30 | "\n" +
31 | "\n" +
32 | "\n" +
33 | "\n" +
34 | "\n" +
35 | "\n");
36 |
37 | final JSONObject expected = JSONObject.fromObject("{@DOMVersion:\"8.0\", @Self:\"d\", TinDocumentDataObject:{" +
38 | "Properties:{" +
39 | "GaijiRefMaps:\"\"} } }");
40 |
41 | assertEquals(expected, actual);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/xml/TestXmlContainingCData.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.xml;
19 |
20 | import org.custommonkey.xmlunit.XMLTestCase;
21 | import org.kordamp.json.JSON;
22 | import org.xml.sax.SAXException;
23 |
24 | import javax.xml.parsers.ParserConfigurationException;
25 | import java.io.IOException;
26 |
27 | public class TestXmlContainingCData extends XMLTestCase {
28 |
29 | public void testXmlWithTypeAttribute() throws IOException, SAXException, ParserConfigurationException {
30 | final String xml = "\n" + "";
31 |
32 | final XMLSerializer tested = new XMLSerializer();
33 | tested.setKeepCData(true);
34 | tested.setTypeHintsEnabled(false);
35 | tested.setRootName("data");
36 |
37 | final JSON jsonRepresentation = tested.read(xml);
38 |
39 | final String result = tested.write(jsonRepresentation);
40 |
41 | assertXMLEqual(xml, result);
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/xml/TestXmlContainingTypeAttribute.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.xml;
19 |
20 | import org.custommonkey.xmlunit.XMLTestCase;
21 | import org.kordamp.json.JSON;
22 | import org.xml.sax.SAXException;
23 |
24 | import javax.xml.parsers.ParserConfigurationException;
25 | import java.io.IOException;
26 |
27 | public class TestXmlContainingTypeAttribute extends XMLTestCase {
28 |
29 | public void testXmlWithTypeAttribute() throws IOException, SAXException, ParserConfigurationException {
30 | final String xml = "value";
31 |
32 | final XMLSerializer tested = new XMLSerializer();
33 | tested.setTypeHintsEnabled(false);
34 | tested.setTypeHintsCompatibility(false);
35 | tested.setRootName("data");
36 |
37 | final JSON jsonRepresentation = tested.read(xml);
38 |
39 | final String result = tested.write(jsonRepresentation);
40 |
41 | assertXMLEqual(xml, result);
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/java/org/kordamp/json/xml/TestXmlWithEntity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * SPDX-License-Identifier: Apache-2.0
3 | *
4 | * Copyright 2006-2024 the original author or authors.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * https://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package org.kordamp.json.xml;
19 |
20 | import org.custommonkey.xmlunit.XMLTestCase;
21 | import org.kordamp.json.JSON;
22 | import org.xml.sax.SAXException;
23 |
24 | import javax.xml.parsers.ParserConfigurationException;
25 | import java.io.IOException;
26 |
27 | public class TestXmlWithEntity extends XMLTestCase {
28 | public void test_convert_xml_with_entity() throws IOException, SAXException, ParserConfigurationException {
29 | String fixture = "\n" +
30 | "" +
31 | "" +
32 | "/
9j/4AAQSkZJRgABAgEASABIAAD/7QAsUGhvdG9zaG9wIDMuMAA4QklNA+0AAAAAABAASAAAAAEA
AQBIAAAAAQAB/" +
33 | "" +
34 | "";
35 |
36 | XMLSerializer xmlSerializer = new XMLSerializer();
37 | xmlSerializer.setEscapeLowerChars(true);
38 | xmlSerializer.setRootName("Description");
39 | xmlSerializer.setTypeHintsEnabled(false);
40 | final JSON json = xmlSerializer.read(fixture);
41 |
42 | final String result = xmlSerializer.write(json);
43 |
44 | assertXMLEqual(fixture, result);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/resources/org/kordamp/json/xml/1735732.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 |
23 | emp1
24 | 2 5
25 |
26 |
27 | emp2
28 | 2
29 |
30 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/resources/org/kordamp/json/xml/1739066.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
22 | http://localhost:0/te stToString
23 |
26 |
30 | tns:GreetMeService
31 |
32 |
35 | tns:GreetMePortType
36 |
37 |
38 |
--------------------------------------------------------------------------------
/subprojects/json-lib-core/src/test/resources/org/kordamp/json/xml/delicious.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
27 |
28 |
29 | del.icio.us/aalmiray/javascript
30 | http://del.icio.us/aalmiray/javascript
31 |
32 |
33 |
34 |
36 |
37 |
38 |
39 |
40 |
42 | Using prototype.js v1.5.0
43 |
44 | http://www.sergiopereira.com/articles/prototype.js.html
45 |
46 | aalmiray
47 | 2007-01-03T19:25:20Z
48 | guide javascript prototype
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------