Skip to content

Commit eab8900

Browse files
committed
feat: add SBXRecord interface for typed entities
1 parent 99a1786 commit eab8900

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.sbxcloud.sbx.model;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
/**
7+
* Base interface for SBX record types.
8+
* <p>
9+
* All SBX records have a {@code _KEY} (primary key) and optional {@code _META} (metadata).
10+
*
11+
* <h2>Usage with Java Records</h2>
12+
* <pre>{@code
13+
* @JsonIgnoreProperties(ignoreUnknown = true)
14+
* public record Contact(
15+
* @JsonProperty("_KEY") String key,
16+
* @JsonProperty("_META") SBXMeta meta,
17+
* String name,
18+
* String email,
19+
* String status
20+
* ) implements SBXRecord {}
21+
* }</pre>
22+
*
23+
* <h2>Creating New Records</h2>
24+
* <pre>{@code
25+
* // For inserts, key and meta are null
26+
* var newContact = new Contact(null, null, "John", "john@example.com", "ACTIVE");
27+
*
28+
* // Or add a convenience constructor
29+
* public record Contact(...) implements SBXRecord {
30+
* public Contact(String name, String email, String status) {
31+
* this(null, null, name, email, status);
32+
* }
33+
* }
34+
* }</pre>
35+
*
36+
* <h2>Accessing Metadata</h2>
37+
* <pre>{@code
38+
* Contact contact = response.results().get(0);
39+
* System.out.println("Key: " + contact.key());
40+
* if (contact.meta() != null) {
41+
* System.out.println("Created: " + contact.meta().createdTime());
42+
* System.out.println("Updated: " + contact.meta().updateTime());
43+
* }
44+
* }</pre>
45+
*
46+
* @see SBXMeta
47+
*/
48+
public interface SBXRecord {
49+
50+
/**
51+
* The unique key for this record ({@code _KEY} in JSON).
52+
*/
53+
@JsonProperty("_KEY")
54+
String key();
55+
56+
/**
57+
* The metadata for this record ({@code _META} in JSON).
58+
* Contains createdTime, updateTime, modelId, modelName, domain.
59+
*/
60+
@JsonProperty("_META")
61+
SBXMeta meta();
62+
}

0 commit comments

Comments
 (0)