但是在objectMapper.writeValueAsString()这个地方,eclipse报了The type com.fasterxml.jackson.core.JsonGenerator cannot be resolved. It is indirectly referenced错误。
出现这种情况是因为我在使用ObjectMapper时,只引入了jackson-databind这个包。解决的办法是需要把jackson-core这个包也引入进来。
具体的原理什么的没有去分析了,后面有时间在好好研究一下Jackson。