Skip to content

Common Types and Enumerations

← JSON Key Configuration | Next: Global Options →


This chapter defines the enumerations and common types used throughout the codec configuration. These types control what, how, and where information is serialized.

ConcernTypes
What to serializeTypeStrategy, IdStrategy, IdKeyMode, SuperTypeSelection
How to format outputSerializationFormat, SuperTypePresentation
Where strategies applyStrategyScope
Deserialization behaviorDeserializationMode, TypeHintMode, FallbackStrategy

1. SerializationFormat

Controls how data is presented (the structure of the output).

java
public enum SerializationFormat {
    /**
     * Simple value output - string, number, or array of simple values.
     * The value itself is directly usable without parsing.
     */
    PLAIN,

    /**
     * Nested object output with configurable keys.
     * The value is a map/object containing structured information.
     */
    STRUCTURED
}

1.1 Format Comparison

FormatSingle ValueArray Value
PLAIN"_type": "Person""_supertype": ["Entity", "Auditable"]
STRUCTURED"_type": { "schema": "...", "type": "..." }"_supertype": [{"schema": "...", "type": "Entity"}, ...]

1.2 When to Use Each Format

Use CaseRecommended FormatReason
Compact output, simple casesPLAINMinimal JSON overhead
Multi-part informationSTRUCTUREDSchema + type together
Multiple ID featuresSTRUCTUREDShow individual feature values
Cross-system interopSTRUCTUREDSelf-documenting output

1.3 Applicability

SerializationFormat applies to these serialization targets:

TargetPLAIN ExampleSTRUCTURED Example
Type"_type": "Person""_type": {"schema": "...", "type": "..."}
ID"_id": "John-Doe""_id": {"firstName": "John", ...}
Reference"_ref": "acme-corp""_ref": {"_type": "...", "uri": "..."}
SuperType["Entity", "Auditable"][{"schema": "...", "type": "Entity"}, ...]

Default: PLAIN

See also: Naming Conventions (section 2) for key naming differences between formats.


2. StrategyScope

Controls where a strategy/format applies in the object hierarchy.

java
public enum StrategyScope {
    /**
     * Apply to all objects in the serialization tree.
     */
    ALL,

    /**
     * Apply only to root-level objects (resource.getContents()).
     */
    ROOT_ONLY,

    /**
     * Apply to root objects and objects reached via containment references.
     */
    ROOT_CONTAINMENT,

    /**
     * Apply to root objects and objects reached via non-containment references.
     */
    ROOT_NON_CONTAINMENT
}

2.1 Scope Visualization

resource.getContents()
├── Person (ROOT)                    ← ROOT_ONLY, ROOT_CONTAINMENT, ROOT_NON_CONTAINMENT, ALL
│   ├── Address (containment)        ← ROOT_CONTAINMENT, ALL
│   │   └── Country (containment)    ← ROOT_CONTAINMENT, ALL
│   └── Company (non-containment)    ← ROOT_NON_CONTAINMENT, ALL
│       └── CEO (containment)        ← ALL only (not root, containment of non-root)

2.2 When to Use Each Scope

ScopeUse Case
ALLConsistent type info throughout (default)
ROOT_ONLYSmart compression - type info only at root, rely on schema for nested
ROOT_CONTAINMENTType info for contained objects, not referenced ones
ROOT_NON_CONTAINMENTType info for references (useful when references are polymorphic)

2.3 Applicability

StrategyScope is used for:

  • codec.typeScope - Where to apply TypeStrategy
  • codec.typeFormatScope - Where to apply type SerializationFormat
  • codec.idScope - Where to apply IdStrategy
  • codec.idFormatScope - Where to apply ID SerializationFormat

Default: ALL

See also: Configuration Resolution (section 5) for how StrategyScope interacts with configuration hierarchy.


3. TypeStrategy

Controls what type information is serialized.

java
public enum TypeStrategy {
    /**
     * Full EMF EClass URI.
     * Example: "http://example.org/person/1.0#//Person"
     */
    URI,

    /**
     * Simple EClass name without package.
     * Example: "Person"
     */
    NAME,

    /**
     * Schema URI and type name as separate pieces.
     * Requires STRUCTURED format for single field, or uses two fields in PLAIN.
     */
    SCHEMA_AND_TYPE,

    /**
     * EMF classifier ID (numeric).
     * Example: "3"
     * WARNING: IDs are positional and may change with model evolution.
     */
    NUMERIC,

    /**
     * No type information serialized.
     * Requires CODEC_ROOT_TYPE hint for deserialization.
     */
    NONE
}

3.1 Strategy Comparison

StrategyPLAIN OutputSTRUCTURED Output
URI"_type": "http://example.org/1.0#//Person""_type": { "uri": "http://..." }
NAME"_type": "Person""_type": { "type": "Person" }
SCHEMA_AND_TYPE"_schema": "http://...", "_type": "Person""_type": { "schema": "http://...", "type": "Person" }
NUMERIC"_type": "3""_type": { "schema": "http://...", "classifier": 3 }
NONE(no type field)(no type field)

3.2 When to Use Each Strategy

StrategyUse CaseAdvantagesDisadvantages
URICross-system, long-term storageSelf-contained, unambiguousVerbose
NAMESingle-package models, APIsReadable, compactAmbiguous if multiple packages have same class name
SCHEMA_AND_TYPEMulti-package with readable typesBoth schema context and readable nameTwo values needed
NUMERICTransient data, compact outputVery compactFragile - IDs change with model evolution
NONEHomogeneous collections, compact APIsMost compactRequires type hint for deserialization

Default: URI

See also: Type Serialization for complete type configuration, Discriminator Mapping for custom type resolution.


4. IdStrategy

Controls how object identity is serialized.

java
public enum IdStrategy {
    /**
     * Use attributes marked with eID="true" in the model.
     * The first eID attribute (or XMI-compatible ID) is used.
     */
    ID_FIELD,

    /**
     * Combine multiple features into a single ID value.
     * Features and separator are configurable.
     */
    COMBINED
}

4.1 Strategy Comparison

StrategyConfigurationExample Output (PLAIN)
ID_FIELDUse model's eID attribute"_id": "john-doe"
COMBINEDfeatures=firstName,lastName, separator=-"_id": "John-Doe"

4.2 When to Use Each Strategy

StrategyUse Case
ID_FIELDModel already has eID attribute, simple ID scheme
COMBINEDNeed composite key from multiple features

Default: ID_FIELD

See also: ID Serialization for complete ID configuration including STRUCTURED format examples.


5. IdKeyMode

Controls what is written to JSON for ID values.

java
public enum IdKeyMode {
    /**
     * Only write the _id field with the computed ID value.
     * Individual ID features are NOT written separately.
     */
    ID_ONLY,

    /**
     * Write both the _id field AND the individual features.
     * Useful when features should be queryable independently.
     */
    BOTH,

    /**
     * Write individual features but NOT the _id field.
     * ID is implicit from the feature values.
     */
    FEATURE_ONLY,

    /**
     * Do not write any ID information.
     */
    NONE
}

5.1 Mode Comparison

ModeOutput for Person{firstName="John", lastName="Doe"}
ID_ONLY{"_id": "John-Doe"}
BOTH{"_id": "John-Doe", "firstName": "John", "lastName": "Doe"}
FEATURE_ONLY{"firstName": "John", "lastName": "Doe"}
NONE{} (no ID fields)

5.2 When to Use Each Mode

ModeUse Case
ID_ONLYCompact output, ID is only needed for references
BOTHFeatures should be queryable, but also need stable ID
FEATURE_ONLYID features are the primary data, no separate ID field needed
NONENo ID serialization required

Default: ID_ONLY

See also: ID Serialization (section 3) for IdKeyMode examples with COMBINED strategy.


6. SuperTypeSelection

Controls which supertypes are included in supertype serialization.

java
public enum SuperTypeSelection {
    /**
     * Include only the immediate supertype.
     */
    SINGLE,

    /**
     * Include all supertypes in the hierarchy.
     */
    ALL,

    /**
     * Include all EMF supertypes (excluding EObject).
     */
    ALL_EMF,

    /**
     * Do not include any supertype information.
     */
    NONE
}

6.1 Selection Comparison

For Customer extends Person extends Entity:

SelectionOutput
SINGLE["Person"]
ALL["Person", "Entity"]
ALL_EMF["Person", "Entity"] (same as ALL for this example)
NONE(no supertype field)

Default: ALL

See also: SuperType Serialization for complete supertype configuration.


7. SuperTypePresentation

Controls how multiple supertypes are presented.

java
public enum SuperTypePresentation {
    /**
     * Supertypes as JSON array.
     */
    ARRAY,

    /**
     * Supertypes as comma-separated string.
     */
    STRING
}

7.1 Presentation Comparison

PresentationOutput
ARRAY"_supertype": ["Person", "Entity"]
STRING"_supertype": "Person,Entity"

Default: ARRAY

See also: SuperType Serialization (section 2) for presentation format configuration.


8. FallbackStrategy

Controls behavior when discriminator mapping cannot resolve a type.

java
public enum FallbackStrategy {
    /**
     * Log WARNING, continue to next resolution step (Type Strategy).
     * This is the default.
     */
    SKIP,

    /**
     * Fail immediately with an error.
     */
    ERROR,

    /**
     * Use fallbackEClass (MUST be set, else ERROR).
     * Does NOT continue to Type Strategy.
     */
    FALLBACK
}

See Discriminator Mapping for detailed fallback behavior.

Default: SKIP


9. DeserializationMode

Controls strictness of deserialization.

java
public enum DeserializationMode {
    /**
     * Fail on unknown fields, require exact type matches.
     */
    STRICT,

    /**
     * Skip unknown fields, allow compatible type coercion.
     */
    LENIENT,

    /**
     * Infer mode from JSON structure.
     */
    AUTO_DETECT
}

Default: AUTO_DETECT

See also: Error Handling for how DeserializationMode affects error reporting.


10. TypeHintMode

Controls how type hints interact with JSON _type fields.

java
public enum TypeHintMode {
    /**
     * Type hint is fallback; JSON _type takes precedence.
     */
    HINT,

    /**
     * Type hint overrides JSON _type (useful for schema migration).
     */
    OVERRIDE
}

Default: HINT

See also: Load/Save Options (section 2) for using type hints during deserialization.


11. Summary Table

EnumValuesDefaultUsed In
SerializationFormatPLAIN, STRUCTUREDPLAINType, ID, Reference, SuperType
StrategyScopeALL, ROOT_ONLY, ROOT_CONTAINMENT, ROOT_NON_CONTAINMENTALLConfig Resolution
TypeStrategyURI, NAME, SCHEMA_AND_TYPE, NUMERIC, NONEURIType
IdStrategyID_FIELD, COMBINEDID_FIELDID
IdKeyModeID_ONLY, BOTH, FEATURE_ONLY, NONEID_ONLYID
SuperTypeSelectionALL, ALL_EMF, SINGLE, NONEALLSuperType
SuperTypePresentationARRAY, STRINGARRAYSuperType
FallbackStrategySKIP, ERROR, FALLBACKSKIPDiscriminator Mapping
DeserializationModeSTRICT, LENIENT, AUTO_DETECTAUTO_DETECTLoad/Save Options
TypeHintModeHINT, OVERRIDEHINTLoad/Save Options

Next: Global Configuration Options →

Released under the EPL-2.0 License. Eclipse Fennec is part of the Eclipse Foundation.