Serializes the object in a uniform matter for storage. Needed for successful CAS calls @return The serialized object as a byte array
()
| 515 | * @return The serialized object as a byte array |
| 516 | */ |
| 517 | @VisibleForTesting |
| 518 | byte[] getStorageJSON() { |
| 519 | // TODO - precalculate size |
| 520 | final ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| 521 | try { |
| 522 | final JsonGenerator json = JSON.getFactory().createGenerator(output); |
| 523 | json.writeStartObject(); |
| 524 | if (tsuid != null && !tsuid.isEmpty()) { |
| 525 | json.writeStringField("tsuid", tsuid); |
| 526 | } |
| 527 | json.writeNumberField("startTime", start_time); |
| 528 | json.writeNumberField("endTime", end_time); |
| 529 | json.writeStringField("description", description); |
| 530 | json.writeStringField("notes", notes); |
| 531 | if (custom == null) { |
| 532 | json.writeNullField("custom"); |
| 533 | } else { |
| 534 | final TreeMap<String, String> sorted_custom = |
| 535 | new TreeMap<String, String>(custom); |
| 536 | json.writeObjectField("custom", sorted_custom); |
| 537 | } |
| 538 | |
| 539 | json.writeEndObject(); |
| 540 | json.close(); |
| 541 | return output.toByteArray(); |
| 542 | } catch (IOException e) { |
| 543 | throw new RuntimeException("Unable to serialize Annotation", e); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * Syncs the local object with the stored object for atomic writes, |
no test coverage detected