-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for multiple languages in geocoding model objects #1025
Conversation
4e0f480
to
ee12d09
Compare
TypeAdapter<String> stringAdapter = this.stringAdapter; | ||
if (stringAdapter == null) { | ||
this.stringAdapter = stringAdapter; | ||
stringAdapter = gson.getAdapter(String.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the adapter always uses String.class
, does it have to be lazily initialized in each method instead once in the class field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the part that I was not sure about.
The code is extracted from generated AutoValue.
There is an instance variable: stringAdapter which will be Lazily initialized.
I am not sure why there is a need to keep a local copy of this. stringAdapter
Decided to keep it as is. I think I should address that part separately.
} | ||
|
||
@Nullable | ||
List<String> readLanguages(@Nullable List<String> languages, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The passed collections references seem to always be null
s and are initialized only here, do we need to pass them in the first place then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe readLanguages
will be called multiple times. In case of CarmenContext json could look like:
"context": [
{
"id": "country.9053006287256050",
"short_code": "us",
"wikidata": "Q30",
"text_ru": "Соединённые Штаты Америки",
"language_ru": "ru",
"text": "Соединённые Штаты Америки",
"language": "ru",
"text_fr": "États-Unis",
"language_fr": "fr"
}
]
}
so it will be called to read:
"language_ru": "ru",
then to read:
"language_fr": "fr"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it be called multiple times with the same list as an argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. JsonReader is parsing each key/value as they come in. We cannot get all the language_*
pairs (and similarly for other pairs and JsonWriter). I believe TypeAdapters are more efficient then JsonSerializer/Deserializer as do not have an intermediate parsed state. Because of that though it is a bit more restrictive.
@@ -48,7 +49,7 @@ | |||
* @since 1.0.0 | |||
*/ | |||
@Keep | |||
public final class Feature implements GeoJson { | |||
public final class Feature implements GeoJson, Serializable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the advantage of making Feature
/FeatureCollection
serializable now? If we'd like to make them serializable in general, why not make GeoJson
implement Serializable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed inconsistency that felt odd, so decided to add it there. I think you are right: we can just add Serializable to GeoJson. Will experiment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decide to remove these changes from this PR.
I think your suggestion is a valid one and should be addressed in a separate PR.
Whoops, didn't mean to approve, only comment. |
cc @kbauhaus as fyi that this is moving |
6d0aea5
to
fdda347
Compare
fdda347
to
a35aa3b
Compare
I think this PR is functionally fine, but the style is off because it comes from generated code. We're going to need to maintain it manually now, so it should be cleaned up before it's merged to |
Thank you for 👀 @LukasPaczos |
I'm thinking about the left comments like unnecessary local object copies, lazy inits, or null checks. |
Lazy init for TypeAdapter does not make sense - agree with you. I do think that some TypeAdapters should be lazily initialized as those fields are rarely used like foBoundingBox, etc. |
This pull request has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
This pull request has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
This pull request has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
This pull request has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
This PR will resolve #446
There were two parts to this PR:
text_{language} fields into a Map (lang -> text string in that language)
Added tests.