Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Fix : MapAdapter to serialize Long keys as integer instead of string#13

Open
gowoonsori wants to merge 1 commit into
marcospassos:masterfrom
gowoonsori:master
Open

Fix : MapAdapter to serialize Long keys as integer instead of string#13
gowoonsori wants to merge 1 commit into
marcospassos:masterfrom
gowoonsori:master

Conversation

@gowoonsori
Copy link
Copy Markdown

@gowoonsori gowoonsori commented May 8, 2026

Hi, thanks for this great library! I've been using it in my project and it works really well.

I found a small issue with MapAdapter and wanted to contribute a fix.

Problem

When a Map has Long type keys, MapAdapter falls through to the else
branch and calls key.toString(), resulting in the key being serialized as a
PHP string (s:) instead of an integer (i:).

For example, a map with key 1L would produce:

  • Before: a:1:{s:1:"1";s:5:"value";}
  • After: a:1:{i:1;s:5:"value";}

Changes

  • Added Long instanceof check in MapAdapter to write integer keys via
    writer.writeKey((long) key)
  • Added writeKey(long) overload in Writer to support long type keys
  • Added test case for Long keys in MapAdapterTest

Notes

This is consistent with the existing writeInteger(Long) method in Writer,
which already serializes Long values using the i: format.

@marcospassos
Copy link
Copy Markdown
Owner

Hi @gowoonsori, this project is no longer actively maintained, and I don't have the time to keep it updated. I'd recommend forking it and maintaining your own version.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants