The exception is: Instantiation of [simple type, c...
# spring
l
The exception is: Instantiation of [simple type, class com.foo.bar.Goalscorer] value failed for JSON property event due to missing (therefore NULL) value for creator parameter event which is a non-nullable type.
The JSON is:
Copy code
[{
	"match_id": "303207",
	"country_id": "222",
	"country_name": "Brazil",
	"league_id": "513",
	"league_name": "Serie B",
	"match_date": "2018-08-29",
	"match_status": "FT",
	"match_time": "01:30",
	"match_hometeam_name": "Oeste FC",
	"match_hometeam_score": "0",
	"match_awayteam_name": "Sao Bento",
	"match_awayteam_score": "1",
	"match_hometeam_halftime_score": "0",
	"match_awayteam_halftime_score": "0",
	"match_hometeam_extra_score": "",
	"match_awayteam_extra_score": "",
	"match_hometeam_penalty_score": "",
	"match_awayteam_penalty_score": "",
	"match_hometeam_system": "",
	"match_awayteam_system": "",
	"match_live": "0",
	"goalscorer": [{
		"time": "80'",
		"home_scorer": "",
		"score": "0 - 1",
		"away_scorer": "F.  Francis  Junior"
	}],
	"cards": [],
	"lineup": {
		"home": {
			"starting_lineups": [],
			"substitutes": [],
			"coach": [],
			"substitutions": []
		},
		"away": {
			"starting_lineups": [],
			"substitutes": [],
			"coach": [],
			"substitutions": []
		}
	},
	"statistics": []
}]
d
Your
Goalscorer
class has an
event
constructor parameter, which must not be null according to your code. In your JSON this parameter is missing.
l
OK, can I create that relationship without the parameter?
d
Well, you need some way of choosing which
Event
should be passed
l
Say, use the
match_id
as the
event_id
in
Goalscorer
?
d
You'll need a custom jackson deserializer most likely.
But deserializing directly into your entity classes is somewhat of an antipattern anyways. You should keep your json representation and database entities separate.
l
Ahh darn, OK, thank you for your help.