Skip to content

The behavior of the @RestHeader annotation is different from the @HeaderParam annotation when the parameter is of type List #31866

@benDeMtp

Description

@benDeMtp

The @RestHeader javadoc says :

/*
* Equivalent of HeaderParam but with optional name.
*/

And the javadoc of HeaderParam say that :


/**
 * Binds the value(s) of a HTTP header to a resource method parameter,
 * resource class field, or resource class bean property. A default value
 * can be specified using the {@link DefaultValue} annotation.
 *
 * The type {@code T} of the annotated parameter, field or property
 * must either:
 * <ol>
 * <li>Be a primitive type</li>
 * <li>Have a constructor that accepts a single {@code String} argument</li>
 * <li>Have a static method named {@code valueOf} or {@code fromString}
 * that accepts a single
 * {@code String} argument (see, for example, {@link Integer#valueOf(String)})</li>
 * <li>Have a registered implementation of {@link javax.ws.rs.ext.ParamConverterProvider}
 * JAX-RS extension SPI that returns a {@link javax.ws.rs.ext.ParamConverter}
 * instance capable of a "from string" conversion for the type.</li>
 * <li>Be {@code List<T>}, {@code Set<T>} or
 * {@code SortedSet<T>}, where {@code T} satisfies 2, 3 or 4 above.
 * The resulting collection is read-only.</li>
 * </ol>
 *
* /

But the behavior of @RestHeader is different when the parameter is a List :

by example a method like that :

Response getSomething(@RestHeader("Prefer") List prefers);

Throw this kind of exception :
ClassCast class java.util.ImmutableCollections$List12 cannot be cast to class java.lang.String (java.util.ImmutableCollections$List12 and java.lang.String are in module java.base of loader 'bootstrap')

since 2.8 and it can be reproduced in 3.0.0.Alpha5

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions