Formats the JSON output for writing to storage. It drops objects we don't need or want to store (such as the UIDMeta objects or the total dps) to save space. It also serializes in order so that we can make a proper CAS call. Otherwise the POJO serializer may place the fields in any order and CAS cal
()
| 498 | * @return A byte array to write to storage |
| 499 | */ |
| 500 | private byte[] getStorageJSON() { |
| 501 | // 256 bytes is a good starting value, assumes default info |
| 502 | final ByteArrayOutputStream output = new ByteArrayOutputStream(256); |
| 503 | try { |
| 504 | final JsonGenerator json = JSON.getFactory().createGenerator(output); |
| 505 | json.writeStartObject(); |
| 506 | json.writeStringField("type", type.toString()); |
| 507 | json.writeStringField("displayName", display_name); |
| 508 | json.writeStringField("description", description); |
| 509 | json.writeStringField("notes", notes); |
| 510 | json.writeNumberField("created", created); |
| 511 | if (custom == null) { |
| 512 | json.writeNullField("custom"); |
| 513 | } else { |
| 514 | json.writeObjectFieldStart("custom"); |
| 515 | for (Map.Entry<String, String> entry : custom.entrySet()) { |
| 516 | json.writeStringField(entry.getKey(), entry.getValue()); |
| 517 | } |
| 518 | json.writeEndObject(); |
| 519 | } |
| 520 | |
| 521 | json.writeEndObject(); |
| 522 | json.close(); |
| 523 | return output.toByteArray(); |
| 524 | } catch (IOException e) { |
| 525 | throw new RuntimeException("Unable to serialize UIDMeta", e); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | // Getters and Setters -------------- |
| 530 |
no test coverage detected