public class Struct
extends java.lang.Object
A structured record containing a set of named fields with values, each field using an independent Schema.
Struct objects must specify a complete Schema up front, and only fields specified in the Schema may be set.
The Struct's put(String, Object) method returns the Struct itself to provide a fluent API for constructing
complete objects:
Schema schema = SchemaBuilder.struct().name("com.example.Person")
.field("name", Schema.STRING_SCHEMA).field("age", Schema.INT32_SCHEMA).build()
Struct struct = new Struct(schema).put("name", "Bobby McGee").put("age", 21)
| Constructor | Description |
|---|---|
Struct(Schema schema) |
Create a new Struct for this
Schema |
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
equals(java.lang.Object o) |
|
java.lang.Object |
get(java.lang.String fieldName) |
Get the value of a field, returning the default value if no value has been set yet and a default value is specified
in the field's schema.
|
java.lang.Object |
get(Field field) |
Get the value of a field, returning the default value if no value has been set yet and a default value is specified
in the field's schema.
|
<T> java.util.List<T> |
getArray(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a List. |
java.lang.Boolean |
getBoolean(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a Boolean. |
byte[] |
getBytes(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a byte[]. |
java.lang.Float |
getFloat32(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a Float. |
java.lang.Double |
getFloat64(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a Double. |
java.lang.Short |
getInt16(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a Short. |
java.lang.Integer |
getInt32(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a Integer. |
java.lang.Long |
getInt64(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a Long. |
java.lang.Byte |
getInt8(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a Byte. |
<K,V> java.util.Map<K,V> |
getMap(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a Map. |
java.lang.String |
getString(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a String. |
Struct |
getStruct(java.lang.String fieldName) |
Equivalent to calling
get(String) and casting the result to a Struct. |
java.lang.Object |
getWithoutDefault(java.lang.String fieldName) |
Get the underlying raw value for the field without accounting for default values.
|
int |
hashCode() |
|
Struct |
put(java.lang.String fieldName,
java.lang.Object value) |
Set the value of a field.
|
Struct |
put(Field field,
java.lang.Object value) |
Set the value of a field.
|
Schema |
schema() |
Get the schema for this Struct.
|
java.lang.String |
toString() |
|
void |
validate() |
Validates that this struct has filled in all the necessary data with valid values.
|
public Schema schema()
public java.lang.Object get(java.lang.String fieldName)
Object and
must be cast to a more specific type.fieldName - the field name to lookuppublic java.lang.Object get(Field field)
Object and
must be cast to a more specific type.field - the field to lookuppublic java.lang.Object getWithoutDefault(java.lang.String fieldName)
fieldName - the field to get the value ofpublic java.lang.Byte getInt8(java.lang.String fieldName)
get(String) and casting the result to a Byte.public java.lang.Short getInt16(java.lang.String fieldName)
get(String) and casting the result to a Short.public java.lang.Integer getInt32(java.lang.String fieldName)
get(String) and casting the result to a Integer.public java.lang.Long getInt64(java.lang.String fieldName)
get(String) and casting the result to a Long.public java.lang.Float getFloat32(java.lang.String fieldName)
get(String) and casting the result to a Float.public java.lang.Double getFloat64(java.lang.String fieldName)
get(String) and casting the result to a Double.public java.lang.Boolean getBoolean(java.lang.String fieldName)
get(String) and casting the result to a Boolean.public java.lang.String getString(java.lang.String fieldName)
get(String) and casting the result to a String.public byte[] getBytes(java.lang.String fieldName)
get(String) and casting the result to a byte[].public <T> java.util.List<T> getArray(java.lang.String fieldName)
get(String) and casting the result to a List.public <K,V> java.util.Map<K,V> getMap(java.lang.String fieldName)
get(String) and casting the result to a Map.public Struct getStruct(java.lang.String fieldName)
get(String) and casting the result to a Struct.public Struct put(java.lang.String fieldName, java.lang.Object value)
DataException if it does not match the field's
Schema.fieldName - the name of the field to setvalue - the value of the fieldput(String, Object) callspublic Struct put(Field field, java.lang.Object value)
DataException if it does not match the field's
Schema.field - the field to setvalue - the value of the fieldput(String, Object) callspublic void validate()
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object