Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Georg Fette
UniWueUtils
Commits
aac4cc99
Commit
aac4cc99
authored
Apr 17, 2019
by
Georg Fette
Browse files
added jsonutil
parent
0a23e6d1
Changes
4
Hide whitespace changes
Inline
Side-by-side
UniWueUtils/pom.xml
View file @
aac4cc99
...
...
@@ -225,6 +225,11 @@
<artifactId>
commons-dbcp2
</artifactId>
<version>
2.3.0
</version>
</dependency>
<dependency>
<groupId>
org.json
</groupId>
<artifactId>
json
</artifactId>
<version>
20180813
</version>
</dependency>
</dependencies>
<build>
<plugins>
...
...
@@ -244,5 +249,5 @@
</plugins>
</build>
<groupId>
UniWueUtils
</groupId>
<version>
0.0.
2
</version>
<version>
0.0.
4
</version>
</project>
\ No newline at end of file
UniWueUtils/src/main/java/de/uniwue/misc/util/JSONUtil.java
0 → 100644
View file @
aac4cc99
package
de.uniwue.misc.util
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
de.uniwue.misc.util.ResourceElem.FieldType
;
public
class
JSONUtil
{
public
static
void
parseJsonObject
(
JSONObject
anObj
,
ResourceElem
container
)
{
for
(
String
aKey
:
anObj
.
keySet
())
{
Object
subObject
=
anObj
.
get
(
aKey
);
ResourceElem
newField
=
new
ResourceElem
();
newField
.
name
=
aKey
;
container
.
fields
.
put
(
aKey
,
newField
);
parseJsonField
(
subObject
,
newField
);
}
}
public
static
void
parseJsonField
(
Object
subObject
,
ResourceElem
newField
)
{
if
(
subObject
instanceof
JSONObject
)
{
newField
.
type
=
FieldType
.
Object
;
JSONObject
jsonObj
=
(
JSONObject
)
subObject
;
parseJsonObject
(
jsonObj
,
newField
);
}
else
if
(
subObject
instanceof
JSONArray
)
{
newField
.
type
=
FieldType
.
Array
;
JSONArray
jsonArray
=
(
JSONArray
)
subObject
;
for
(
int
j
=
0
;
j
<
jsonArray
.
length
();
j
++)
{
Object
anArrayElem
=
jsonArray
.
get
(
j
);
ResourceElem
newArrayElem
=
new
ResourceElem
();
newArrayElem
.
name
=
newField
.
name
;
newField
.
arrayElems
.
add
(
newArrayElem
);
parseJsonField
(
anArrayElem
,
newArrayElem
);
}
}
else
if
(
subObject
instanceof
String
)
{
newField
.
type
=
FieldType
.
Primitive
;
newField
.
value
=
subObject
.
toString
();
}
else
if
(
subObject
instanceof
Number
)
{
newField
.
type
=
FieldType
.
Primitive
;
newField
.
value
=
subObject
.
toString
();
}
}
}
UniWueUtils/src/main/java/de/uniwue/misc/util/ResourceElem.java
0 → 100644
View file @
aac4cc99
package
de.uniwue.misc.util
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
public
class
ResourceElem
{
public
String
name
;
public
String
value
;
public
HashMap
<
String
,
ResourceElem
>
fields
=
new
HashMap
<
String
,
ResourceElem
>();
public
List
<
ResourceElem
>
arrayElems
=
new
ArrayList
<
ResourceElem
>();
public
static
enum
FieldType
{
Primitive
,
Array
,
Object
}
public
FieldType
type
;
public
boolean
isArray
()
{
return
type
==
FieldType
.
Array
;
}
public
String
toString
()
{
if
(
type
==
FieldType
.
Primitive
)
{
return
name
+
" : "
+
value
;
}
else
{
return
name
;
}
}
}
UniWueUtils/src/main/java/de/uniwue/misc/util/StringUtilsUniWue.java
View file @
aac4cc99
...
...
@@ -12,13 +12,13 @@ public class StringUtilsUniWue {
aCol
.
add
(
aColumn
.
toLowerCase
());
}
}
public
static
String
cleanStringFromSpecialCharacters
(
String
extID
)
{
String
result
=
extID
;
result
=
result
.
replaceAll
(
"[^a-zA-Z0-9_]"
,
"_"
);
return
result
;
}
public
static
String
concat
(
String
[]
someStrings
,
String
separator
)
{
if
(
someStrings
==
null
)
return
null
;
...
...
@@ -76,4 +76,8 @@ public class StringUtilsUniWue {
return
result
;
}
public
static
String
firstUpperCase
(
String
aString
)
{
return
aString
.
substring
(
0
,
1
).
toUpperCase
()
+
aString
.
substring
(
1
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment