flink-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yassin Marzouki <yassmar...@gmail.com>
Subject Variable not initialized in the open() method of RichMapFunction
Date Fri, 22 Jul 2016 14:49:18 GMT
Hi everyone,

I want to convert a stream of json strings to POJOs using Jackson, so I did
the following:

.map(new RichMapFunction<String, Request>() {

    private ObjectMapper objectMapper;

        public void open() {
            objectMapper = new ObjectMapper();

             public Request map(String value) throws Exception {
                 return objectMapper.readValue(value, Request.class);

But this code gave me a NullPointerException because the objectMapper was
not initialized successfully.

1. Isn't the open() method supposed to be called before map() and
initialize objectMapper?
2. I figured out that initializing objectMapper before the open() method
resolves the problem, and that it works also with a simple MapFunction. In
that case, is there an advantage for using a RichMapFunction?


View raw message