1
1
/*
2
- * Copyright (c) 2000, 2022 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2000, 2025 , Oracle and/or its affiliates.
3
3
*
4
4
* Licensed under the Universal Permissive License v 1.0 as shown at
5
5
* https://oss.oracle.com/licenses/upl.
33
33
34
34
import static jakarta .ws .rs .core .MediaType .APPLICATION_JSON ;
35
35
36
+
36
37
/**
37
38
* Provider responsible for converting Java collections to a JSON formatted
38
39
* stream.
42
43
@ Provider
43
44
@ Produces (APPLICATION_JSON )
44
45
public class JsonCollectionWriter
45
- implements MessageBodyWriter <Object >
46
+ implements MessageBodyWriter <Collection <?> >
46
47
{
47
48
// ----- constructors ---------------------------------------------------
48
49
@@ -56,7 +57,7 @@ public JsonCollectionWriter()
56
57
/**
57
58
* Construct a JsonCollectionWriter instance.
58
59
*
59
- * @param registry marshaller registry to use
60
+ * @param registry marshaller registry to use
60
61
*/
61
62
public JsonCollectionWriter (MarshallerRegistry registry )
62
63
{
@@ -67,21 +68,21 @@ public JsonCollectionWriter(MarshallerRegistry registry)
67
68
68
69
@ Override
69
70
public boolean isWriteable (Class <?> clz , Type type , Annotation [] aAnnotation ,
70
- MediaType mediaType )
71
+ MediaType mediaType )
71
72
{
72
73
return Collection .class .isAssignableFrom (clz );
73
74
}
74
75
75
76
@ Override
76
- public long getSize (Object col , Class <?> clz , Type type , Annotation [] aAnnotation ,
77
- MediaType mediaType )
77
+ public long getSize (Collection <?> col , Class <?> clz , Type type , Annotation [] aAnnotation ,
78
+ MediaType mediaType )
78
79
{
79
80
return -1 ;
80
81
}
81
82
82
83
@ Override
83
- public void writeTo (Object oCol , Class <?> clz , Type type , Annotation [] aAnnotation ,
84
- MediaType mediaType , MultivaluedMap <String , Object > httpHeaders , OutputStream stream )
84
+ public void writeTo (Collection <?> oCol , Class <?> clz , Type type , Annotation [] aAnnotation ,
85
+ MediaType mediaType , MultivaluedMap <String , Object > httpHeaders , OutputStream stream )
85
86
throws IOException , WebApplicationException
86
87
{
87
88
MarshallerRegistry registry = m_marshallerRegistry ;
@@ -91,11 +92,11 @@ public void writeTo(Object oCol, Class<?> clz, Type type, Annotation[] aAnnotati
91
92
}
92
93
93
94
EntryWriter entryWriter = new EntryWriter (registry );
94
- PrintStream out = new PrintStream (stream );
95
+ PrintStream out = new PrintStream (stream );
95
96
out .print ("[" );
96
97
97
98
boolean first = true ;
98
- for (Object o : ( Collection ) oCol )
99
+ for (Object o : oCol )
99
100
{
100
101
if (o != null )
101
102
{
0 commit comments