json2pojo 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pojo_creator.rb +18 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a87241c0485afab7a960edc87811688b90f51ec6
|
4
|
+
data.tar.gz: b07c803d977f4f57b79e0e22d8cf00611af561ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db1db607724683d993ae5592f4b2573aea407b6cd503337742734dfe4c48c7f1e03c9e3258e6f199297e45661ca42fff524448c5fc27b20c5bde9321557a0856
|
7
|
+
data.tar.gz: 4bd4bcf8f2706b392cf9b8501ca7e300f3015d3efb98be084ab15a522e8a9a46bf734ce8838db64e94c32637645f8e42647d787930d44eb898eea87498595919
|
data/lib/pojo_creator.rb
CHANGED
@@ -2,7 +2,7 @@ require "json"
|
|
2
2
|
|
3
3
|
class PojoCreator
|
4
4
|
|
5
|
-
VERSION = '0.3.
|
5
|
+
VERSION = '0.3.1'
|
6
6
|
|
7
7
|
def initialize(class_name)
|
8
8
|
@class_name = get_class_name(class_name)
|
@@ -20,15 +20,15 @@ class PojoCreator
|
|
20
20
|
prop_string = ""
|
21
21
|
|
22
22
|
json.keys.each do |property|
|
23
|
-
|
23
|
+
prop_prefix = "\t@JsonProperty(\"#{property}\")\tprivate "
|
24
|
+
class_name = json[property].class.to_s
|
25
|
+
if (class_name == "Hash")
|
24
26
|
@additional_classes << "class #{get_class_name(property)} {" + get_properties(json[property]) + "}"
|
25
|
-
|
26
|
-
elsif(json[property].class.to_s == "Array")
|
27
|
+
elsif (class_name == "Array")
|
27
28
|
@additional_classes << "class #{get_class_name(property)} {" + get_properties(json[property][0]) + "}"
|
28
|
-
prop_string += "\t@JsonProperty(\"#{property}\")\tprivate List<#{get_class_name(property)}> #{get_field_name(property)};"
|
29
|
-
else
|
30
|
-
prop_string += "\t@JsonProperty(\"#{property}\")\tprivate #{get_type(json[property])} #{get_field_name(property)};"
|
31
29
|
end
|
30
|
+
prop_string += prop_prefix + get_type(json, property) + " " + get_field_name(property) + ";"
|
31
|
+
|
32
32
|
end
|
33
33
|
prop_string
|
34
34
|
|
@@ -50,21 +50,26 @@ class PojoCreator
|
|
50
50
|
snake_case_to_class_name(property)
|
51
51
|
end
|
52
52
|
|
53
|
-
def get_type(
|
54
|
-
|
53
|
+
def get_type(json, key)
|
54
|
+
|
55
55
|
begin
|
56
|
-
Date.parse(
|
56
|
+
Date.parse(json[key])
|
57
57
|
return "Date"
|
58
58
|
rescue
|
59
59
|
|
60
60
|
end
|
61
61
|
|
62
|
-
|
62
|
+
class_name = json[key].class.to_s
|
63
|
+
if class_name == "Fixnum"
|
63
64
|
return "Integer"
|
64
|
-
elsif
|
65
|
+
elsif class_name == "Float"
|
65
66
|
return "Float"
|
66
|
-
elsif
|
67
|
+
elsif class_name == "FalseClass" or class_name == "TrueClass"
|
67
68
|
return "Boolean"
|
69
|
+
elsif class_name == "Hash"
|
70
|
+
return get_class_name(key)
|
71
|
+
elsif class_name == "Array"
|
72
|
+
return "List<" + get_class_name(key) + ">"
|
68
73
|
else
|
69
74
|
return "String"
|
70
75
|
end
|