fix: handle string-or-array MAC address fields from ABM API#2
Open
robbiet480 wants to merge 1 commit intozchee:mainfrom
Open
fix: handle string-or-array MAC address fields from ABM API#2robbiet480 wants to merge 1 commit intozchee:mainfrom
robbiet480 wants to merge 1 commit intozchee:mainfrom
Conversation
Apple's ABM API inconsistently returns wifiMacAddress, bluetoothMacAddress, ethernetMacAddress, IMEI, and MEID as either a JSON string or an array of strings depending on the device. This causes unmarshal failures when the response format doesn't match the expected []string type. Add a StringOrStrings type implementing UnmarshalerFrom that handles both a single JSON string and a JSON array of strings, as well as null values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Apple's ABM API inconsistently returns
wifiMacAddress,bluetoothMacAddress,ethernetMacAddress,IMEI, andMEIDas either a JSON string or an array of strings depending on the device. This causes unmarshal failures when the response format doesn't match the expected[]stringtype.This PR adds a
StringOrStringstype (with underlying type[]string) that implements thejson.UnmarshalerFrominterface for thego-json-experiment/jsonlibrary. The custom unmarshaler handles three cases:["AA:BB:CC:DD:EE:FF"]) — unmarshaled as-is"AA:BB:CC:DD:EE:FF") — wrapped into a single-element sliceThe following fields in
OrgDeviceAttributesare changed from[]stringtoStringOrStrings:IMEIMEIDWifiMacAddressBluetoothMacAddressEthernetMacAddressSince
StringOrStringshas an underlying type of[]string, this change is backward-compatible for code that indexes or iterates over these fields.Test plan
[]stringcontinues to compile🤖 Generated with Claude Code