Closed afarhan39 closed 3 weeks ago
@afarhan39 what is the specific bug you're facing with that? Our internal usage of valueOf
e.g. here applies needed transformations so that values can get mapped as expected. I assume you should either do the same if you for some reason need to perform this mapping manually or just use our high-level APIs like:
if (lineLayer.lineJoin == LineJoin.ROUND) {
// do something
}
Our APIs were actually designed for users not to mess up with strings and provide high-level typed APIs.
I had a usecase that require to store IconAnchor
into data class
below is the code
@Parcelize
data class CustomLocationMarkerData(
val locationData: LocationData,
val iconType: Constants.IconType,
val locationName: String? = null,
val iconText: String? = null,
val id: String? = null,
val anchorPoint: String? = null,
val sortKey: Double? = null
) : Parcelable {
companion object {
val anchorCenter = IconAnchor.CENTER.value
}
}
and since the workaround is storing string value, when I remap again via IconAnchor.valueOf(anchorPoint)
, its throwing error IconAnchor.valueOf does not support center
Doesn't enum value should be the same? I don't get why the string value is different
Consider valueOf
as an internal utility function. I explained in https://github.com/mapbox/mapbox-maps-android/issues/2503#issuecomment-2437601119 how it works in our SDK. The reason why it was designed like that is because this code is generated and it was easier for us to match the way of how we generate actual enum declaration and related valueOf
function. In your case you can just map it the same way we do here.
gotcha, that will work. thanks!
Environment
Observed behavior and steps to reproduce
From path:
com/mapbox/maps/extension/style/layers/properties/generated/Property.kt
Similar things also can be observed in
TextAnchor
both enum value and valueOf string value is not same, for example: center != CENTER
So, what happened currently, its always throwing error
IconAnchor.valueOf does not support center
Expected behavior
I'm expecting both string should match, ie val CENTER = IconAnchor("CENTER") which later can correctly mapped via
IconAnchor.valueOf("CENTER")