Kotlin based common tools.
-
Add it in your root build.gradle at the end of repositories:
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
-
Add the dependency:
dependencies { implementation 'com.github.VerstSiu.common-tools:jackson:1.0' implementation 'com.github.VerstSiu.common-tools:tools:1.0' }
-
Json text builder:
Start text building with
JsonTextBuilder.json
orJsonTextBuilder.jsonArray
and buildjson/jsonArray
content with following apis.-
Raw values:
text("Tony") // \"Tony\" number(1) // 1 numberText("0.00001") // 0.00001 boolean(true) // true
-
Wrap with keys:
text("name", "Tony") // \"name\":\"Tony\"
-
Wrap as next item:
nextText("Tony") // ,\"Tony\"
-
Wrap with keys as next item:
nextText("name", "Tony") // ,\"name\":\"Tony\"
-
Wrap as json object:
json { text("name", "Tony") nextNumber("age", 11) } // {\"name\":\"Tony\",\"age\",11}
-
Wrap as json array:
jsonArray { jsonArray("fruits", listOf("apple", "pear", "orange")) { text(it) } } // {\"fruits\":[\"apple\",\"pear\",\"orange\"]}
-
Wrap as custom json array:
jsonArray { jsonArray("info") { text("Tony") nextNumber(1) } } // {\"info\":[\"Tony\",1]}
-
Copyright(c) 2018 VerstSiu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.