首页 \ 问答 \ Java:Jackson数据绑定无法从JSON文件映射整个类(Java: Jackson Data Binding Fails to Map Entire Class from JSON File)

Java:Jackson数据绑定无法从JSON文件映射整个类(Java: Jackson Data Binding Fails to Map Entire Class from JSON File)

我试图将JSON文件映射到名为Tweets.java的java类,我能够从JSON文件的第一部分(推文类)绑定和检索数据,但Jackson ObjectMapper无法映射嵌套Tweets.Java类(用户类和实体类)。

这是我访问JSON被绑定到的类的方法:

WeatherDatabaseCreator.java

    //Read in files to be parsed.
    for (int i = 0; i < twitterFiles.size(); i++) {

        File twitterFile = twitterFiles.get(i);
        WeatherTweetParser wtp = new WeatherTweetParser(twitterFile);
        wtp.mapJavaObject();

        tws = new Tweets();
        tweets = tws.getTweets();

        System.out.print(tweets.size());

        tweetIndex = 0;

        System.out.println("Parsing and inserting twitter file '" + twitterFile.getAbsolutePath() + "'...");

    //Step through all the tweets in each file, using the TweetParser class.
    while (true) {
        tweet = tweets.get(tweetIndex);
        user = tweet.new User();
        entity = tweet.new Entities();

        userMentions = entity.getUserMentions();
        hashtags = entity.getHashtags();

        if (tweet.getText() == null) {
            break;
        }
        numParsed++;

        Boolean success = wdbm.insertTweet(tweet, user);
        if (success == true) {
            numInserted++;
        }

        if (entity.getNumHashtags() > 0){

            for (int j = 0; j < entity.getNumHashtags(); j++) {
                wdbm.insertHashtag(tweet, hashtags.get(j)); 
            }   
        }

        if (entity.getNumUserMentions() > 0) {

            for (int k = 0; k < entity.getNumUserMentions(); k++) {
                wdbm.insertReference(tweet, userMentions.get(k));
            }
        }

        if (numParsed % UPDATE_INTERVAL == 0) {
            System.out.println(numParsed + " tweets parsed. " + numInserted + " tweets inserted into database...");
        }

        tweetIndex++;
    }

这是JSON文件的一部分。 该文件由一系列推文组成,其中包含一些嵌套类,包括用户信息和实体信息(主题标签,用户提及)。 这里我包含了数组的两个元素:

2014-01-03-11-03.terms.json

{
"tweets": [
    {
        "filter_level": "medium",
        "contributors": null,
        "text": "U know your ice fishing at home when ur snacks are sandwiches,chips,dips,beef jerky and all the goodies instead of just a case of beer #mom",
        "geo": null,
        "retweeted": false,
        "in_reply_to_screen_name": null,
        "truncated": false,
        "lang": "en",
        "entities": {
            "symbols": [

            ],
            "urls": [

            ],
            "hashtags": [
                {
                    "text": "mom",
                    "indices": [
                        135,
                        139
                    ]
                }
            ],
            "user_mentions": [

            ]
        },
        "in_reply_to_status_id_str": null,
        "id": 419137025376145408,
        "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone<\/a>",
        "in_reply_to_user_id_str": null,
        "favorited": false,
        "in_reply_to_status_id": null,
        "retweet_count": 0,
        "created_at": "Fri Jan 03 16:03:48 +0000 2014",
        "in_reply_to_user_id": null,
        "favorite_count": 0,
        "id_str": "419137025376145408",
        "place": null,
        "user": {
            "location": "",
            "default_profile": false,
            "profile_background_tile": true,
            "statuses_count": 5411,
            "lang": "en",
            "profile_link_color": "17EBCF",
            "profile_banner_url": "https://pbs.twimg.com/profile_banners/408240224/1384838946",
            "id": 408240224,
            "following": null,
            "protected": false,
            "favourites_count": 4222,
            "profile_text_color": "333333",
            "description": "It is what it is, no more, no less. Trust in the Lord. BSU Softball #5.  My whole being is happy - Psalm 16:9",
            "verified": false,
            "contributors_enabled": false,
            "profile_sidebar_border_color": "FFFFFF",
            "name": "Nicole Anne",
            "profile_background_color": "C0DEED",
            "created_at": "Wed Nov 09 05:03:58 +0000 2011",
            "default_profile_image": false,
            "followers_count": 452,
            "profile_image_url_https": "https://pbs.twimg.com/profile_images/413270299925164033/mWiJBKP2_normal.jpeg",
            "geo_enabled": true,
            "profile_background_image_url": "http://a0.twimg.com/profile_background_images/698793822/14d9ce538d96b435ad4449d5385a3ec1.jpeg",
            "profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/698793822/14d9ce538d96b435ad4449d5385a3ec1.jpeg",
            "follow_request_sent": null,
            "url": null,
            "utc_offset": -32400,
            "time_zone": "Alaska",
            "notifications": null,
            "profile_use_background_image": true,
            "friends_count": 634,
            "profile_sidebar_fill_color": "DDEEF6",
            "screen_name": "NDupay",
            "id_str": "408240224",
            "profile_image_url": "http://pbs.twimg.com/profile_images/413270299925164033/mWiJBKP2_normal.jpeg",
            "listed_count": 1,
            "is_translator": false
        },
        "coordinates": null
    },
    {
        "filter_level": "medium",
        "contributors": null,
        "text": "Just watched DeBlasio shovel snow for the cameras and I have to say, his form is terrible. Looks a bit inexperienced.",
        "geo": null,
        "retweeted": false,
        "in_reply_to_screen_name": null,
        "truncated": false,
        "lang": "en",
        "entities": {
            "symbols": [

            ],
            "urls": [

            ],
            "hashtags": [

            ],
            "user_mentions": [

            ]
        },
        "in_reply_to_status_id_str": null,
        "id": 419137026458673152,
        "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone<\/a>",
        "in_reply_to_user_id_str": null,
        "favorited": false,
        "in_reply_to_status_id": null,
        "retweet_count": 0,
        "created_at": "Fri Jan 03 16:03:48 +0000 2014",
        "in_reply_to_user_id": null,
        "favorite_count": 0,
        "id_str": "419137026458673152",
        "place": null,
        "user": {
            "location": "",
            "default_profile": false,
            "profile_background_tile": false,
            "statuses_count": 2609,
            "lang": "en",
            "profile_link_color": "FF8000",
            "id": 163686045,
            "following": null,
            "protected": false,
            "favourites_count": 204,
            "profile_text_color": "333333",
            "description": "Love learning, Hockey #NYR, music and photography. My family is my whole life.",
            "verified": false,
            "contributors_enabled": false,
            "profile_sidebar_border_color": "EEEEEE",
            "name": "Steven Marques",
            "profile_background_color": "ACDED6",
            "created_at": "Wed Jul 07 01:26:25 +0000 2010",
            "default_profile_image": false,
            "followers_count": 56,
            "profile_image_url_https": "https://pbs.twimg.com/profile_images/378800000795958214/5e3ff928282ad692a36e941e5c5ff628_normal.jpeg",
            "geo_enabled": false,
            "profile_background_image_url": "http://abs.twimg.com/images/themes/theme18/bg.gif",
            "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme18/bg.gif",
            "follow_request_sent": null,
            "url": null,
            "utc_offset": -18000,
            "time_zone": "Eastern Time (US & Canada)",
            "notifications": null,
            "profile_use_background_image": true,
            "friends_count": 58,
            "profile_sidebar_fill_color": "F6F6F6",
            "screen_name": "SMGafanha",
            "id_str": "163686045",
            "profile_image_url": "http://pbs.twimg.com/profile_images/378800000795958214/5e3ff928282ad692a36e941e5c5ff628_normal.jpeg",
            "listed_count": 2,
            "is_translator": false
        },
        "coordinates": null
    },

这是JSON文件映射到的Java类,后面是映射JSON的类:

Tweets.java

public class Tweets {

private ArrayList<Tweet> tweets;

public Tweets() {
    tweets = new ArrayList<Tweet>();
}

public ArrayList<Tweet> getTweets() {
    return tweets;
}

public void setTweets(ArrayList<Tweet> tweets) {
    this.tweets = tweets;
}

public static class Tweet {

    private String text;
    @JsonProperty("source")
    private String postMethod;
    @JsonProperty("created_at")
    private String time;
    @JsonProperty("id")
    private String ID;

    public Tweet() {

    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getID() {
        return ID;
    }

    public void setID(String iD) {
        ID = iD;
    }

    public String getPostMethod() {
        return postMethod;
    }

    public void setPostMethod(String postMethod) {
        this.postMethod = postMethod;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public class User {

        private String location;
        @JsonProperty("screen_name")
        private String user;
        @JsonProperty("time_zone")
        private String timeZone;
        @JsonProperty("description")
        private String accountDescription;

        public User(){

        }

        public String getLocation() {
            return location;
        }

        public void setLocation(String location) {
            this.location = location;
        }

        public String getUser() {
            return user;
        }

        public void setUser(String user) {
            this.user = user;
        }

        public String getTimeZone() {
            return timeZone;
        }

        public void setTimeZone(String timeZone) {
            this.timeZone = timeZone;
        }

        public String getAccountDescription() {
            return accountDescription;
        }

        public void setAccountDescription(String accountDescription) {
            this.accountDescription = accountDescription;
        }
    }
    public class Entities {

        @JsonProperty("user_mentions")
        ArrayList<UserMention> userMentions;
        @JsonProperty("hashtags")
        ArrayList<Hashtag> hashtags;

        public Entities() {
            userMentions = new ArrayList<UserMention>();
            hashtags = new ArrayList<Hashtag>();                
        }

        public ArrayList<UserMention> getUserMentions() {
            return userMentions;
        }

        public int getNumUserMentions() {
            return userMentions.size();
        }

        public UserMention getUserMention(int index) {
            return userMentions.get(index);
        }

        public void setUserMentions(ArrayList<UserMention> userMentions) {
            this.userMentions = userMentions;
        }

        public ArrayList<Hashtag> getHashtags() {
            return hashtags;
        }

        public int getNumHashtags() {
            return hashtags.size();
        }

        public Hashtag getHashtag(int index) {
            return hashtags.get(index);
        }

        public void setHashtags(ArrayList<Hashtag> hashtags) {
            this.hashtags = hashtags;
        }

        public class UserMention {

            @JsonProperty("screen_name")
            private String userRef;

            public UserMention() {

            }

            public String getUserRef() {
                return userRef;
            }

            public void setUserRef(String userRef) {
                this.userRef = userRef;
            }
        }
        public class Hashtag {

            @JsonProperty("text")
            private String hashText;

            public Hashtag() {

            }

            public String getHashText() {
                return hashText;
            }

            public void setHashText(String hashText) {
                this.hashText = hashText;
            }
        }
    }
}


WeatherTweetParser.java

public class WeatherTweetParser {

private static File twitterFile;

public WeatherTweetParser(File twitterFile) {
    WeatherTweetParser.twitterFile = twitterFile;
}

public Tweets mapJavaObject() {

    Tweets ret = null;
    Path jsonFile = twitterFile.toPath();
    byte[] jsonData = null;

    try {
        jsonData = Files.readAllBytes(jsonFile);
    } catch (IOException e1) {
        e1.printStackTrace();
    }


    System.out.println("Mapping JSON to WeatherTweet Class.");

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    try {
        ret = (Tweets) mapper.readValue(jsonData, Tweets.class);
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("Finished Mapping of JSON File.");

    return ret;
}

public static void main(String[] args) {

    new WeatherTweetParser(twitterFile);
}   

这是控制台输出:

//Right before event passing the data to the method to enter into the db, 
//and right after each tweet is grabbed in WeatherDatabaseCreator.java    

username: null
location: null
time zone: null
account description: null

//Right Before inserting into database.

username: null
time/date: Jan 03 2014 11:03:48
text: RT @_PumpsAndJays: It's winter, right?
location: null
. . .
timezone = null

TL:DR :所以它看起来像我用来映射JSON文件的类不存储用户和实体(我已经查看了后者,这也没有工作,即所有空值),但它存储推文信息(即时间,文本等)。 问题是:为什么WeatherTweetParser.java映射是java类的一部分而不是全部?


I am trying to map a JSON file to a java class called Tweets.java, and I am able to bind and retrieve the data from the first part of the JSON file (the tweet class) but the Jackson ObjectMapper is failing to map the nested classes of Tweets.Java (the classes user and entities).

Here is the method where I am accessing the class that the JSON is being binded to:

WeatherDatabaseCreator.java

    //Read in files to be parsed.
    for (int i = 0; i < twitterFiles.size(); i++) {

        File twitterFile = twitterFiles.get(i);
        WeatherTweetParser wtp = new WeatherTweetParser(twitterFile);
        wtp.mapJavaObject();

        tws = new Tweets();
        tweets = tws.getTweets();

        System.out.print(tweets.size());

        tweetIndex = 0;

        System.out.println("Parsing and inserting twitter file '" + twitterFile.getAbsolutePath() + "'...");

    //Step through all the tweets in each file, using the TweetParser class.
    while (true) {
        tweet = tweets.get(tweetIndex);
        user = tweet.new User();
        entity = tweet.new Entities();

        userMentions = entity.getUserMentions();
        hashtags = entity.getHashtags();

        if (tweet.getText() == null) {
            break;
        }
        numParsed++;

        Boolean success = wdbm.insertTweet(tweet, user);
        if (success == true) {
            numInserted++;
        }

        if (entity.getNumHashtags() > 0){

            for (int j = 0; j < entity.getNumHashtags(); j++) {
                wdbm.insertHashtag(tweet, hashtags.get(j)); 
            }   
        }

        if (entity.getNumUserMentions() > 0) {

            for (int k = 0; k < entity.getNumUserMentions(); k++) {
                wdbm.insertReference(tweet, userMentions.get(k));
            }
        }

        if (numParsed % UPDATE_INTERVAL == 0) {
            System.out.println(numParsed + " tweets parsed. " + numInserted + " tweets inserted into database...");
        }

        tweetIndex++;
    }

Here is part of the JSON File. The file is made up of an array of tweets, with some nested classes including the user info and entity info (hashtags, user mentions). Here I included two elements of the array:

2014-01-03-11-03.terms.json

{
"tweets": [
    {
        "filter_level": "medium",
        "contributors": null,
        "text": "U know your ice fishing at home when ur snacks are sandwiches,chips,dips,beef jerky and all the goodies instead of just a case of beer #mom",
        "geo": null,
        "retweeted": false,
        "in_reply_to_screen_name": null,
        "truncated": false,
        "lang": "en",
        "entities": {
            "symbols": [

            ],
            "urls": [

            ],
            "hashtags": [
                {
                    "text": "mom",
                    "indices": [
                        135,
                        139
                    ]
                }
            ],
            "user_mentions": [

            ]
        },
        "in_reply_to_status_id_str": null,
        "id": 419137025376145408,
        "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone<\/a>",
        "in_reply_to_user_id_str": null,
        "favorited": false,
        "in_reply_to_status_id": null,
        "retweet_count": 0,
        "created_at": "Fri Jan 03 16:03:48 +0000 2014",
        "in_reply_to_user_id": null,
        "favorite_count": 0,
        "id_str": "419137025376145408",
        "place": null,
        "user": {
            "location": "",
            "default_profile": false,
            "profile_background_tile": true,
            "statuses_count": 5411,
            "lang": "en",
            "profile_link_color": "17EBCF",
            "profile_banner_url": "https://pbs.twimg.com/profile_banners/408240224/1384838946",
            "id": 408240224,
            "following": null,
            "protected": false,
            "favourites_count": 4222,
            "profile_text_color": "333333",
            "description": "It is what it is, no more, no less. Trust in the Lord. BSU Softball #5.  My whole being is happy - Psalm 16:9",
            "verified": false,
            "contributors_enabled": false,
            "profile_sidebar_border_color": "FFFFFF",
            "name": "Nicole Anne",
            "profile_background_color": "C0DEED",
            "created_at": "Wed Nov 09 05:03:58 +0000 2011",
            "default_profile_image": false,
            "followers_count": 452,
            "profile_image_url_https": "https://pbs.twimg.com/profile_images/413270299925164033/mWiJBKP2_normal.jpeg",
            "geo_enabled": true,
            "profile_background_image_url": "http://a0.twimg.com/profile_background_images/698793822/14d9ce538d96b435ad4449d5385a3ec1.jpeg",
            "profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/698793822/14d9ce538d96b435ad4449d5385a3ec1.jpeg",
            "follow_request_sent": null,
            "url": null,
            "utc_offset": -32400,
            "time_zone": "Alaska",
            "notifications": null,
            "profile_use_background_image": true,
            "friends_count": 634,
            "profile_sidebar_fill_color": "DDEEF6",
            "screen_name": "NDupay",
            "id_str": "408240224",
            "profile_image_url": "http://pbs.twimg.com/profile_images/413270299925164033/mWiJBKP2_normal.jpeg",
            "listed_count": 1,
            "is_translator": false
        },
        "coordinates": null
    },
    {
        "filter_level": "medium",
        "contributors": null,
        "text": "Just watched DeBlasio shovel snow for the cameras and I have to say, his form is terrible. Looks a bit inexperienced.",
        "geo": null,
        "retweeted": false,
        "in_reply_to_screen_name": null,
        "truncated": false,
        "lang": "en",
        "entities": {
            "symbols": [

            ],
            "urls": [

            ],
            "hashtags": [

            ],
            "user_mentions": [

            ]
        },
        "in_reply_to_status_id_str": null,
        "id": 419137026458673152,
        "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone<\/a>",
        "in_reply_to_user_id_str": null,
        "favorited": false,
        "in_reply_to_status_id": null,
        "retweet_count": 0,
        "created_at": "Fri Jan 03 16:03:48 +0000 2014",
        "in_reply_to_user_id": null,
        "favorite_count": 0,
        "id_str": "419137026458673152",
        "place": null,
        "user": {
            "location": "",
            "default_profile": false,
            "profile_background_tile": false,
            "statuses_count": 2609,
            "lang": "en",
            "profile_link_color": "FF8000",
            "id": 163686045,
            "following": null,
            "protected": false,
            "favourites_count": 204,
            "profile_text_color": "333333",
            "description": "Love learning, Hockey #NYR, music and photography. My family is my whole life.",
            "verified": false,
            "contributors_enabled": false,
            "profile_sidebar_border_color": "EEEEEE",
            "name": "Steven Marques",
            "profile_background_color": "ACDED6",
            "created_at": "Wed Jul 07 01:26:25 +0000 2010",
            "default_profile_image": false,
            "followers_count": 56,
            "profile_image_url_https": "https://pbs.twimg.com/profile_images/378800000795958214/5e3ff928282ad692a36e941e5c5ff628_normal.jpeg",
            "geo_enabled": false,
            "profile_background_image_url": "http://abs.twimg.com/images/themes/theme18/bg.gif",
            "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme18/bg.gif",
            "follow_request_sent": null,
            "url": null,
            "utc_offset": -18000,
            "time_zone": "Eastern Time (US & Canada)",
            "notifications": null,
            "profile_use_background_image": true,
            "friends_count": 58,
            "profile_sidebar_fill_color": "F6F6F6",
            "screen_name": "SMGafanha",
            "id_str": "163686045",
            "profile_image_url": "http://pbs.twimg.com/profile_images/378800000795958214/5e3ff928282ad692a36e941e5c5ff628_normal.jpeg",
            "listed_count": 2,
            "is_translator": false
        },
        "coordinates": null
    },

Here is the Java class that the JSON file is mapped to, followed by the class mapping the JSON:

Tweets.java

public class Tweets {

private ArrayList<Tweet> tweets;

public Tweets() {
    tweets = new ArrayList<Tweet>();
}

public ArrayList<Tweet> getTweets() {
    return tweets;
}

public void setTweets(ArrayList<Tweet> tweets) {
    this.tweets = tweets;
}

public static class Tweet {

    private String text;
    @JsonProperty("source")
    private String postMethod;
    @JsonProperty("created_at")
    private String time;
    @JsonProperty("id")
    private String ID;

    public Tweet() {

    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getID() {
        return ID;
    }

    public void setID(String iD) {
        ID = iD;
    }

    public String getPostMethod() {
        return postMethod;
    }

    public void setPostMethod(String postMethod) {
        this.postMethod = postMethod;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public class User {

        private String location;
        @JsonProperty("screen_name")
        private String user;
        @JsonProperty("time_zone")
        private String timeZone;
        @JsonProperty("description")
        private String accountDescription;

        public User(){

        }

        public String getLocation() {
            return location;
        }

        public void setLocation(String location) {
            this.location = location;
        }

        public String getUser() {
            return user;
        }

        public void setUser(String user) {
            this.user = user;
        }

        public String getTimeZone() {
            return timeZone;
        }

        public void setTimeZone(String timeZone) {
            this.timeZone = timeZone;
        }

        public String getAccountDescription() {
            return accountDescription;
        }

        public void setAccountDescription(String accountDescription) {
            this.accountDescription = accountDescription;
        }
    }
    public class Entities {

        @JsonProperty("user_mentions")
        ArrayList<UserMention> userMentions;
        @JsonProperty("hashtags")
        ArrayList<Hashtag> hashtags;

        public Entities() {
            userMentions = new ArrayList<UserMention>();
            hashtags = new ArrayList<Hashtag>();                
        }

        public ArrayList<UserMention> getUserMentions() {
            return userMentions;
        }

        public int getNumUserMentions() {
            return userMentions.size();
        }

        public UserMention getUserMention(int index) {
            return userMentions.get(index);
        }

        public void setUserMentions(ArrayList<UserMention> userMentions) {
            this.userMentions = userMentions;
        }

        public ArrayList<Hashtag> getHashtags() {
            return hashtags;
        }

        public int getNumHashtags() {
            return hashtags.size();
        }

        public Hashtag getHashtag(int index) {
            return hashtags.get(index);
        }

        public void setHashtags(ArrayList<Hashtag> hashtags) {
            this.hashtags = hashtags;
        }

        public class UserMention {

            @JsonProperty("screen_name")
            private String userRef;

            public UserMention() {

            }

            public String getUserRef() {
                return userRef;
            }

            public void setUserRef(String userRef) {
                this.userRef = userRef;
            }
        }
        public class Hashtag {

            @JsonProperty("text")
            private String hashText;

            public Hashtag() {

            }

            public String getHashText() {
                return hashText;
            }

            public void setHashText(String hashText) {
                this.hashText = hashText;
            }
        }
    }
}


WeatherTweetParser.java

public class WeatherTweetParser {

private static File twitterFile;

public WeatherTweetParser(File twitterFile) {
    WeatherTweetParser.twitterFile = twitterFile;
}

public Tweets mapJavaObject() {

    Tweets ret = null;
    Path jsonFile = twitterFile.toPath();
    byte[] jsonData = null;

    try {
        jsonData = Files.readAllBytes(jsonFile);
    } catch (IOException e1) {
        e1.printStackTrace();
    }


    System.out.println("Mapping JSON to WeatherTweet Class.");

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    try {
        ret = (Tweets) mapper.readValue(jsonData, Tweets.class);
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("Finished Mapping of JSON File.");

    return ret;
}

public static void main(String[] args) {

    new WeatherTweetParser(twitterFile);
}   

And here is the console output:

//Right before event passing the data to the method to enter into the db, 
//and right after each tweet is grabbed in WeatherDatabaseCreator.java    

username: null
location: null
time zone: null
account description: null

//Right Before inserting into database.

username: null
time/date: Jan 03 2014 11:03:48
text: RT @_PumpsAndJays: It's winter, right?
location: null
. . .
timezone = null

TL:DR: So it looks like the class I am using for mapping the JSON file to is not storing the user and entities (I have looked into the latter and that is not working either, i.e. all null values), but it is storing the tweet information (i.e. time, text, etc.). The question is: why is the WeatherTweetParser.java mapping part of the the java class but not all of it?


原文:
更新时间:2021-09-21 13:09

最满意答案

您完全在那里重新定义了app.user模块。
如果要将其他项附加到现有模块,请将第二个参数省略到.module()

angular.module('app.user').run(..)

You're entirely redefining your app.user module there.
If you want to attach additional items to an existing module, leave out the second parameter to .module():

angular.module('app.user').run(..)

相关问答

更多
  • 在这种情况下是重要的顺序。 您需要先加载您的应用 beforeEach(module("app")); 然后覆盖MyService定义。 beforeEach( module({ "MyService": { log: function(message) { console.log("MyFakeService called: " + message); } } }) ); 否则,最后会注册并使用应用服务实施。 工作示例在这里 - 查看控制 ...
  • 您可以在JavaScript中使用setTimeout()和clearTimeout()函数。 功能用途: setTimeout: setTimeout(function, time);` //function is the function to execute //time is the duration to wait (in milisecods) before executing the function clearTimeout: clearTimeout(id);` //id is the ...
  • 异常不会首先发生,您只会首先看到异常的打印输出。 如果首先发生异常,您将永远无法看到其余的输出。 原因是你的程序中输出了System.err (来自你的例外)和System.out 。 这些打印到屏幕的顺序没有定义,因此您可以按不同的顺序获取它们。 The exception doesn't happen first, you are just seeing the printout of the exception first. Had the exception happened first, you ...
  • 我相信您可以使用以下模式制作依赖性承诺解析,其中setData链将在.main完成,并且当我们在.main.app解析getData时将满足。 无需在.run()执行此操作,相反,下面是对我认为您要完成的内容的简单解释... .factory('MyFactory', function($http, $q) { function setData() { var deferred = $q.defer(); $http.get('/endpoint').succe ...
  • 我得到了用户组的一些支持。 所以then块可以是空的。 rule "rule name" when ....... then end I got some support from the user group. So the then block can be empty. rule "rule name" when ....... then end
  • 目前,您正在运行通用python,并使用for和if代替向量化熊猫操作,例如通过与另一系列的逻辑索引有条件地创建列(即系列)。 考虑首先将DAX_Logic和DAX_Logic_1作为DAX数据框中的新列添加到其他行中,从而允许您使用loc创建Daily_Return列: DAX = pd.io.data.DataReader("^GDAXI","yahoo",start,end) # NEW COLUMNS (NOT SEPARATE SERIES) DAX['DAX_Logic'] = DAX['Ope ...
  • 好吧,经过一个美好的夜晚,答案很简单...... 因为我正在进行手动引导,在我的karma.conf文件中,我简单地排除了文件所在的位置。 Karma.conf files: [ 'lib/angular-mocks/angular-mocks.js', 'src/js/**/*.js', 'test/test.js' ], // list of files to exclude exclude: [ 'src/js/bootstrap.js' ], Well, afte ...
  • 类的静态初始化通常在第一次发生以下事件之一时发生: 创建了一个类的实例, 调用类的静态方法, 分配了类的静态字段, 使用非恒定静态场,或[...] 您目前没有执行上述任何操作。 所以,通过更换 Class class1 = A.class; System.out.println(class1); 以此为例 A object = new A(); 会给你你的结果。 A class's static initialization normally happens immediately before ...
  • 两个always块创建两个并行执行的进程。 两个进程都会阻止等待上升的clk事件。 当事件发生时,两个进程都将安排恢复。 但是,Verilog / SystemVerilog仿真器使用一个事件队列来序列化应该同时发生的所有事件。 您无法预测首先安排哪个进程; 这是一个模拟竞赛条件。 在实践中,模拟器的一个特定版本将始终选择一个进程在另一个之前,因此您将始终看到相同的结果。 但是如果您切换到其他工具,或者甚至更改工具中的某些选项以进行调试或优化,则结果可能会发生变化。 The two always block ...
  • 您完全在那里重新定义了app.user模块。 如果要将其他项附加到现有模块,请将第二个参数省略到.module() : angular.module('app.user').run(..) You're entirely redefining your app.user module there. If you want to attach additional items to an existing module, leave out the second parameter to .module() ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)