The World’s Largest Online Community for Developers

'; android - Invalid network request with retrofit - LavOzs.Com

Sorry I know the question does't make sense, but I just can't figure out how to ask the question. I'm using model class that extend RealmObject, serialization by Gson. When I make a request, I send this json:

{"clothing_item_ids": [],
  "date": "2020-01-17 02:19:41 -0500",
  "location": {
   "id": 0
"name": "Good event",
 "tag_ids": []

But I want to send it without the location object when location is null. I can't figure out if the problem came from the way I implemented the Realm, Please help and excuse my ignorance on the matter.

@Parcel(implementations = {LocationRealmProxy.class}, value = Parcel.Serialization.FIELD, analyze = {Location.class})
public class Location extends RealmObject {

public int id;
public String city;
public String postalCode;
public String state;
public String street;

public Location() {

public Location(Location location) { =; =;
    this.postalCode = location.postalCode;
    this.state = location.state;
    this.street = location.street;

Here's the event class:

@Parcel(implementations = {EventRealmProxy.class}, value = Parcel.Serialization.FIELD, analyze = {Event.class})
public class Event extends RealmObject implements Serializable {

public static final String DATE_FIELD = "timestamp";
public String id;
public String date;
public Date timestamp;
public String image;
public String name;

public RealmList<ClothingItem> eventClothingItems;

public Location location;

public RealmList<Tag> tags;

public Event() {
    timestamp = new Date();
    eventClothingItems = new RealmList<>();
    location = new Location();
    tags = new RealmList<>();

public Event(Event event) {
    eventClothingItems = new RealmList<>();
    location = new Location();
    tags = new RealmList<>(); =; =;
    this.image = event.image; =;
    this.location = new Location(event.location);


public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Event event = (Event) o;
    return id.equals(;

public int hashCode() {
    return Objects.hash(id);

This is the Request model

public class CreateEventRequestModel  {
public String name;
public String date;
public Location location;
public List<Integer> clothingItemIds;
public List<Integer> tagIds;

private CreateEventRequestModel() {

public CreateEventRequestModel(Event event) {
    if (event == null) {
    } =; =;
    this.location = event.location;
    this.tagIds = new ArrayList<>();
    this.clothingItemIds = new ArrayList<>();
    if (event.tags != null) {
        for (Tag tag : event.tags) {

    if (event.eventClothingItems != null) {
        for (ClothingItem clothingItem : event.eventClothingItems) {

Help me please figure out what's the problem here, why can't location have all his field as null, or how can I check when location is valid(field should not be empty, or all field should be null or remove location object).

Why does my exception handler not trap Android SQLite insert error?
How to POST raw whole JSON in the body of a Retrofit request?
How to log request and response body with Retrofit-Android?
How to handle Dynamic JSON in Retrofit?
How to set timeout in Retrofit library?
Unable to create converter for my class in Android Retrofit library
Logging with Retrofit 2
Retrofit 2 - Dynamic URL
How to implement parcelable with my custom class containing Hashmap and SparseArray?