Pessoal estou tendo problemas para persistir uma classe News no MongoDB e recebendo o seguinte erro logo abaixo.
Segue todas as classes pertinentes.
Desde já agradeço a colaboração.
package br.com.ucsal.monografia.controller;
import java.util.List;
import br.com.ucsal.monografia.model.HashTag;
import br.com.ucsal.monografia.model.News;
import br.com.ucsal.monografia.service.HashTagService;
import br.com.ucsal.monografia.service.NewsService;
import br.com.ucsal.monografia.twitter.TwitterLoader;
public class CargaNews {
private static void save(List<News> newss) {
NewsService newsService = new NewsService();
for (News news : newss) {
newsService.save(news);
}
}
}
package br.com.ucsal.monografia.service;
import java.util.List;
import java.util.Map;
import br.com.caelum.vraptor.ioc.Component;
import br.com.ucsal.monografia.dao.NewsDao;
import br.com.ucsal.monografia.model.News;
@Component
public class NewsService {
private NewsDao dao = new NewsDao();
public void save(News news) {
dao.save(news);
}
}
package br.com.ucsal.monografia.dao;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import br.com.ucsal.monografia.converter.NewsConverter;
import br.com.ucsal.monografia.model.News;
import com.mongodb.DBObject;
public class NewsDao extends EntityDao<News> {
public NewsDao() {
super(News.class);
}
public void save(News news) {
Map<String, Object> mapNews = new NewsConverter().converterToMap(news);
save(mapNews);
}
}
package br.com.ucsal.monografia.converter;
import java.util.HashMap;
import java.util.Map;
import br.com.ucsal.monografia.model.Feed;
import br.com.ucsal.monografia.model.News;
import br.com.ucsal.monografia.model.NewsType;
import br.com.ucsal.monografia.model.TwitterModel;
import com.mongodb.DBObject;
public class NewsConverter {
public Map<String, Object> converterToMap(News news) {
Map<String, Object> mapNews = new HashMap<String, Object>();
mapNews.put("twitterModel", news.getTwitterModel());
mapNews.put("feed", news.getFeed());
mapNews.put("newsType", news.getNewsType());
return mapNews;
}
}
package br.com.ucsal.monografia.model;
import java.io.Serializable;
public class TwitterModel implements Serializable{
private static final long serialVersionUID = 7686683331955611044L;
private String twitt;
public TwitterModel() {
}
public String getTwitt() {
return twitt;
}
public void setTwitt(String twitt) {
this.twitt = twitt;
}
}
package br.com.ucsal.monografia.model;
import java.io.Serializable;
public class News implements Serializable{
private static final long serialVersionUID = 7686683331955611044L;
private String id;
private TwitterModel twitterModel;
private Feed feed;
private NewsType newsType;
public News(TwitterModel twitterModel, Feed feed, NewsType newsType) {
this.twitterModel = twitterModel;
this.feed = feed;
this.newsType = newsType;
}
public News() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public TwitterModel getTwitterModel() {
return twitterModel;
}
public TwitterModel getTwitter() {
return twitterModel;
}
public void setTwitterModel(TwitterModel twitterModel) {
this.twitterModel = twitterModel;
}
public Feed getFeed() {
return feed;
}
public void setFeed(Feed feed) {
this.feed = feed;
}
public NewsType getNewsType() {
return newsType;
}
public void setNewsType(NewsType newsType) {
this.newsType = newsType;
}
}
Exception in thread "main" java.lang.IllegalArgumentException: can't serialize class br.com.ucsal.monografia.model.TwitterModel
at org.bson.BSONEncoder._putObjectField(BSONEncoder.java:188)
at org.bson.BSONEncoder.putObject(BSONEncoder.java:119)
at org.bson.BSONEncoder.putObject(BSONEncoder.java:65)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:131)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:97)
at com.mongodb.DBCollection.insert(DBCollection.java:75)
at com.mongodb.DBCollection.save(DBCollection.java:545)
at com.mongodb.DBCollection.save(DBCollection.java:523)
at br.com.ucsal.monografia.dao.EntityDao.save(EntityDao.java:39)
at br.com.ucsal.monografia.dao.NewsDao.save(NewsDao.java:20)
at br.com.ucsal.monografia.service.NewsService.save(NewsService.java:16)
at br.com.ucsal.monografia.controller.CargaNews.save(CargaNews.java:32)
at br.com.ucsal.monografia.controller.CargaNews.main(CargaNews.java:23)