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

ParameterNamesModule not registering? #98

Closed
AugustNagro opened this issue Jan 27, 2019 · 1 comment
Closed

ParameterNamesModule not registering? #98

AugustNagro opened this issue Jan 27, 2019 · 1 comment

Comments

@AugustNagro
Copy link

AugustNagro commented Jan 27, 2019

I created a simple program that tests the ParameterNamesModule in java 8, jackson version 2.9.7. Unfortunately I receive the error "Cannot construct instance of Main$Track (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator).

This same example works fine when manually annotating the constructor with @JsonCreator, and parameters with @JsonParameter.

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;

import java.io.IOException;

import static com.fasterxml.jackson.databind.PropertyNamingStrategy.SNAKE_CASE;

public class Main {

    public static final class Track {
        public final int id;
        public final String name;
        public final String artist;

        public Track(int id, String name, String artist) {
            this.id = id;
            this.name = name;
            this.artist = artist;
        }

        @Override
        public String toString() {
            return String.format("id: %d, name: %s, artist: %s", id, name, artist);
        }
    }

    public static void main(String[] args) throws IOException {
        ObjectMapper om = new ObjectMapper()
                .registerModule(new ParameterNamesModule())
                .registerModule(new Jdk8Module())
                .registerModule(new JavaTimeModule())
                .setPropertyNamingStrategy(SNAKE_CASE);

        String json = "{\"id\": 345, \"name\": \"Inside Out\", \"artist\": \"Spoon\"}";
        Track t = om.readValue(json, Track.class);
        System.out.println(t);
    }
}

Is the module not being registered? Or am I not using ParamNamesModule correctly?

@AugustNagro
Copy link
Author

Did not see that compiling with -parameters was required 🤦‍♂️

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