Skip to content

fix: handle string-or-array MAC address fields from ABM API#2

Open
robbiet480 wants to merge 1 commit intozchee:mainfrom
CampusTech:fix/string-or-strings-mac-fields
Open

fix: handle string-or-array MAC address fields from ABM API#2
robbiet480 wants to merge 1 commit intozchee:mainfrom
CampusTech:fix/string-or-strings-mac-fields

Conversation

@robbiet480
Copy link

@robbiet480 robbiet480 commented Mar 4, 2026

Summary

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.

This PR adds a StringOrStrings type (with underlying type []string) that implements the json.UnmarshalerFrom interface for the go-json-experiment/json library. The custom unmarshaler handles three cases:

  • JSON array of strings (["AA:BB:CC:DD:EE:FF"]) — unmarshaled as-is
  • JSON string ("AA:BB:CC:DD:EE:FF") — wrapped into a single-element slice
  • JSON null — set to nil

The following fields in OrgDeviceAttributes are changed from []string to StringOrStrings:

  • IMEI
  • MEID
  • WifiMacAddress
  • BluetoothMacAddress
  • EthernetMacAddress

Since StringOrStrings has an underlying type of []string, this change is backward-compatible for code that indexes or iterates over these fields.

Test plan

  • Verify unmarshaling a device response where MAC fields are returned as arrays
  • Verify unmarshaling a device response where MAC fields are returned as single strings
  • Verify unmarshaling a device response where MAC fields are null
  • Confirm existing code using these fields as []string continues to compile

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant