json2pojo 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pojo_creator.rb +18 -13
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed8bb0a57399fc41a817393d8a2b527bd53f7155
4
- data.tar.gz: ab2eee94d3fe62cfebbdbac9a1b92e17d04a103b
3
+ metadata.gz: a87241c0485afab7a960edc87811688b90f51ec6
4
+ data.tar.gz: b07c803d977f4f57b79e0e22d8cf00611af561ab
5
5
  SHA512:
6
- metadata.gz: 057b59d341ded8eb3fa4838bc2a89a2534646b21c997c346b345fd31c4e589981e82d8f061af52f9d02f376179167afe8559c5afefa7dd6036740add71ee0d7e
7
- data.tar.gz: d5e09427bfee05985c576d865a26aef359e876effeb3ff49a4bd897d1a85a0f97ad6483b8cdfcfa51aed00d67b3ae281bed8d962e92b4a6a332bc8af66990f65
6
+ metadata.gz: db1db607724683d993ae5592f4b2573aea407b6cd503337742734dfe4c48c7f1e03c9e3258e6f199297e45661ca42fff524448c5fc27b20c5bde9321557a0856
7
+ data.tar.gz: 4bd4bcf8f2706b392cf9b8501ca7e300f3015d3efb98be084ab15a522e8a9a46bf734ce8838db64e94c32637645f8e42647d787930d44eb898eea87498595919
@@ -2,7 +2,7 @@ require "json"
2
2
 
3
3
  class PojoCreator
4
4
 
5
- VERSION = '0.3.0'
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
- if (json[property].class.to_s == "Hash")
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
- prop_string += "\t@JsonProperty(\"#{property}\")\tprivate #{get_class_name(property)} #{get_field_name(property)};"
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(value)
54
-
53
+ def get_type(json, key)
54
+
55
55
  begin
56
- Date.parse(value)
56
+ Date.parse(json[key])
57
57
  return "Date"
58
58
  rescue
59
59
 
60
60
  end
61
61
 
62
- if value.class.to_s == "Fixnum"
62
+ class_name = json[key].class.to_s
63
+ if class_name == "Fixnum"
63
64
  return "Integer"
64
- elsif value.class.to_s == "Float"
65
+ elsif class_name == "Float"
65
66
  return "Float"
66
- elsif value.class.to_s == "FalseClass" or value.class.to_s == "TrueClass"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json2pojo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Balazs Mester