bluelinelabs / bluelinelabs/LoganSquare

Allow constructor injection.

Open
#3 13 comments 4 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.2k
Forks
303
PR merge metrics
No merged PRs in 30d

Description

Oftentimes you want your model object to be immutable so you don't want to make your fields public or provide setters. Would it be possible to support constructor injection for this usecase? Something like:

``` java
@JsonObject
public class Image {

@JsonField(name = "_id")
private int imageId;

@JsonField
private String format;

@JsonField
private String url;

@JsonField
private String description;

@JsonField(name = "similar_images")
private List similarImages;

// Not sure if the arguments need to be annotated instead/as well.
@JsonConstructor
public Image(int imageId, String format, String url, String description, List similarImages) {
this.imageId = imageId;
this.format = foramt;
this.url = url;
this.description = description;
this.similarImages = similarImages;
}

public int getImageId() {
return getImageId;
}

public String getFormat() {
return format;
}

public String getUrl() {
return url;
}

public List getSimilarImages() {
return Collections.unmodifiableList(similarImages);
}
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue names no source files, tests, or entry points. Start by locating LoganSquare's annotation processing and deserialization paths, then define how @JsonConstructor parameters map to the existing @JsonField names and add coverage showing immutable Image objects can be constructed from JSON.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
mobile-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.