import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.core.JsonParseException
import com.fasterxml.jackson.databind.ObjectMapper
import org.apache.spark.{SparkContext, SparkConf}
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonCreator;
import java.sql.Date
import java.text.SimpleDateFormat
import org.slf4j.LoggerFactory
@JsonCreator
case class JsonLong{
@JsonProperty("fdn") var fdn: String = null
@JsonProperty("type") var tpy: String= null
@JsonProperty("vid") var vid: String = null
@JsonProperty("version") var version: String = null
@JsonProperty("device_id") var device_id: String = null
@JsonProperty("ip") var ip: String = null
@JsonProperty("timestamp") var timestamp: Long = 0L
}
def jsonString(logjson:String):JsonLong ={
val mapper = new ObjectMapper()
val record = mapper.readValue(logjson, classOf[JsonLong])
record
}
val jsoninput = "{"fdn":"FDNB2023750","type":"0","vid":"2246195","version":"1.0","device_id":"HM+NOTE+1TD_0c-1d-af-7e-1e-a3_865813020970745","ip":"106.118.164.215","timestamp":1463847764}"
val jsonRDD = jsonString(jsoninput)
报错为com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class $iwC$$iwC$JsonLong]: can not instantiate from JSON object (need to add/enable type information?)
at [Source: {"fdn":"FDNB2023750","type":"0","vid":"2246195","version":"1.0","device_id":"HM+NOTE+1TD_0c-1d-af-7e-1e-a3_865813020970745","ip":"106.118.164.215","timestamp":1463847764}; line: 1, column: 2]
我明明已经定义了所有字段了,为啥还报这个错误~~
类的字段没有set和get方法
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。