Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whiteboard Specification for Jakarta™ RESTful Web Services - incorrect snippet #53

Open
fipro78 opened this issue Feb 7, 2024 · 0 comments

Comments

@fipro78
Copy link

fipro78 commented Feb 7, 2024

I am trying to understand the Whiteboard Specification for Jakarta™ RESTful Web Services and write a blog post about it. I cam across the following snippet and wanted to try it out.

@JakartarsExtension
@JakartarsName("configProvider")
@Component
public class ConfigProvider implements ContextResolver {
    
    private ObjectMapper mapper = new ObjectMapper();
    
    public <T> getContext(Class<T> clazz) {
        if(ObjectMapper.class.equals(clazz)) {
            return mapper;
        }
        return null;
    }
}

The snippet seems to be incorrect. If I copy it into an IDE it shows compile errors. And from looking at the ContextResolver interface, it also seems to be intended to look differently. IMHO it should look similar to the following class:

@JakartarsExtension
@JakartarsName("configProvider")
@Provider
public class ConfigProvider implements ContextResolver<ObjectMapper> {
    
    private ObjectMapper mapper; 
    
    public CustomObjectMapperProvider() {
    	this.mapper = new ObjectMapper();
    	this.mapper.enable(SerializationFeature.INDENT_OUTPUT);
    }
    
    public ObjectMapper getContext(Class<?> clazz) {
        return mapper;
    }
}

Of course I am not sure if the snippet in the spec is based on some older JAX-RS specification. But with the current reference implementation, it does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant