Tag: 映射器

Java Hadoop Mapper如何发送多个值

我的映射器需要发送以下元组: 我希望将减少发送者作为密钥发送给reducer,并将prodID和速率作为值一起发送,因为它们是减少阶段所需的。 这是最好的方法吗? public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String[] col = value.toString().split(“,”); custID.set(col[0]); data.set(col[1] + “,” + col[2]); context.write(custID, data); } public void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException { for (Text val : values) { String[] temp = val.toString().split(“,”); Text rate = new Text(temp[1]); […]

如何有效地将org.json.JSONObject映射到POJO?

以前一定要问过这个问题,但我找不到。 我正在使用第三方库来检索JSON格式的数据。 该库以org.json.JSONObject向我提供数据。 我想将此JSONObject映射到POJO(Plain Old Java Object)以获得更简单的访问/代码。 对于映射,我目前以这种方式使用Jackson库中的ObjectMapper : JSONObject jsonObject = //… ObjectMapper mapper = new ObjectMapper(); MyPojoClass myPojo = mapper.readValue(jsonObject.toString(), MyPojoClass.class); 根据我的理解,上面的代码可以得到显着优化,因为目前已经解析的JSONObject的数据再次被送入带有JSONObject.toString()方法的序列化 – 反序列化链,然后送到ObjectMapper 。 我想避免这两个转换( toString()和解析)。 有没有办法使用JSONObject将其数据直接映射到POJO?