2121package land .oras ;
2222
2323import com .fasterxml .jackson .annotation .JsonCreator ;
24+ import com .fasterxml .jackson .annotation .JsonIgnore ;
2425import com .fasterxml .jackson .annotation .JsonInclude ;
2526import com .fasterxml .jackson .annotation .JsonProperty ;
2627import com .fasterxml .jackson .annotation .JsonPropertyOrder ;
3233import java .util .Objects ;
3334import land .oras .utils .Const ;
3435import land .oras .utils .JsonUtils ;
36+ import org .jspecify .annotations .NonNull ;
3537import org .jspecify .annotations .Nullable ;
3638
3739/**
@@ -70,7 +72,42 @@ private Index(
7072 @ JsonProperty (Const .JSON_PROPERTY_MANIFESTS ) List <ManifestDescriptor > manifests ,
7173 @ JsonProperty (Const .JSON_PROPERTY_ANNOTATIONS ) Map <String , String > annotations ,
7274 @ JsonProperty (Const .JSON_PROPERTY_SUBJECT ) Subject subject ) {
73- this (schemaVersion , mediaType , artifactType , manifests , annotations , subject , null , null , null );
75+ super (
76+ null ,
77+ null ,
78+ mediaType ,
79+ annotations != null && !annotations .isEmpty () ? Map .copyOf (annotations ) : null ,
80+ artifactType ,
81+ null ,
82+ null );
83+ this .schemaVersion = schemaVersion ;
84+ this .manifests = manifests ;
85+ this .descriptor = null ;
86+ this .subject = subject ;
87+ }
88+
89+ private Index (
90+ int schemaVersion ,
91+ String mediaType ,
92+ ArtifactType artifactType ,
93+ List <ManifestDescriptor > manifests ,
94+ Map <String , String > annotations ,
95+ Subject subject ,
96+ ManifestDescriptor descriptor ,
97+ String registry ,
98+ String json ) {
99+ super (
100+ null ,
101+ null ,
102+ mediaType ,
103+ annotations ,
104+ artifactType != null ? artifactType .getMediaType () : null ,
105+ registry ,
106+ json );
107+ this .schemaVersion = schemaVersion ;
108+ this .descriptor = descriptor ;
109+ this .subject = subject ;
110+ this .manifests = manifests ;
74111 }
75112
76113 private Index (
@@ -139,6 +176,15 @@ public List<ManifestDescriptor> unspecifiedPlatforms() {
139176 .orElse (null );
140177 }
141178
179+ @ Override
180+ @ JsonIgnore
181+ public @ NonNull ArtifactType getArtifactType () {
182+ if (artifactType != null ) {
183+ return ArtifactType .from (artifactType );
184+ }
185+ return ArtifactType .unknown ();
186+ }
187+
142188 /**
143189 * Get the artifact type as string for JSON serialization
144190 * @return The artifact type as string
@@ -185,7 +231,15 @@ public Index withNewManifests(ManifestDescriptor manifest) {
185231 }
186232 newManifests .add (manifest );
187233 return new Index (
188- schemaVersion , mediaType , artifactType , newManifests , annotations , subject , descriptor , registry , json );
234+ schemaVersion ,
235+ mediaType ,
236+ ArtifactType .from (artifactType ),
237+ newManifests ,
238+ annotations ,
239+ subject ,
240+ descriptor ,
241+ registry ,
242+ json );
189243 }
190244
191245 @ Override
@@ -210,7 +264,7 @@ public ManifestDescriptor getDescriptor() {
210264 * @param artifactType The artifact type
211265 * @return The index
212266 */
213- public Index withArtifactType (String artifactType ) {
267+ public Index withArtifactType (ArtifactType artifactType ) {
214268 return new Index (
215269 schemaVersion , mediaType , artifactType , manifests , annotations , subject , descriptor , registry , json );
216270 }
@@ -274,7 +328,8 @@ public static Index fromPath(Path path) {
274328 * @return The index
275329 */
276330 public static Index fromManifests (List <ManifestDescriptor > descriptors ) {
277- return new Index (2 , Const .DEFAULT_INDEX_MEDIA_TYPE , null , descriptors , null , null , null , null , null );
331+ return new Index (
332+ 2 , Const .DEFAULT_INDEX_MEDIA_TYPE , (ArtifactType ) null , descriptors , null , null , null , null , null );
278333 }
279334
280335 @ Override
0 commit comments