Revize e3d5fc53
Přidáno uživatelem Jan Havlíček před více než 4 roky(ů)
project/Deserializer/src/Converter.java | ||
---|---|---|
46 | 46 |
} |
47 | 47 |
|
48 | 48 |
private String convert(byte[] buffer) { |
49 |
String json = ""; |
|
49 | 50 |
try { |
50 | 51 |
System.out.println("Deserialization begins."); |
51 | 52 |
jdeserialize deserializer = new jdeserialize(buffer); |
... | ... | |
55 | 56 |
List<content> cntnts = deserializer.getContent(); |
56 | 57 |
|
57 | 58 |
// testing with only first of the contents |
58 |
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); |
|
59 |
String json = ow.writeValueAsString(cntnts.get(0)); |
|
60 |
|
|
61 |
System.out.println("Task completed."); |
|
62 |
return json; |
|
59 |
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); |
|
60 |
|
|
61 |
for(content cnt : cntnts) |
|
62 |
{ |
|
63 |
if(cnt != null) |
|
64 |
{ |
|
65 |
json += cnt.simpleFormatToString(); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
System.out.println("Task completed."); |
|
70 |
|
|
71 |
//just for tests |
|
72 |
//System.out.println(json); |
|
73 |
|
|
74 |
return json; |
|
63 | 75 |
} catch (IOException e) { |
64 | 76 |
System.out.println("An error occurred while processing!"); |
65 | 77 |
e.printStackTrace(); |
Také k dispozici: Unified diff
#7794
The jdeserializer.instance type of content gives correct format of output data (JSON-like) through method simpleFormatToString() : String
Works only with primitive data types though