-
Notifications
You must be signed in to change notification settings - Fork 40
feat: Introduce MixpanelApi Builder pattern and expose JsonSerializer option #51
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
base: master
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This PR introduces a flexible Builder pattern for MixpanelAPI configuration and moves Jackson serialization support to a separate optional extension module. The changes maintain full backward compatibility while providing improved performance options for high-volume use cases.
Key Changes
- Builder Pattern: New fluent API for MixpanelAPI configuration with support for all constructor parameters (custom endpoints, gzip compression, feature flags, custom serializers)
- JSON Serializer Abstraction: Introduced
JsonSerializerinterface withOrgJsonSerializeras the default implementation, allowing custom serialization strategies - Jackson Extension Module: New
mixpanel-java-extension-jacksonartifact providing 2-5x performance improvement for large batches (50+ messages), eliminating automatic classpath detection in favor of explicit opt-in
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/main/java/com/mixpanel/mixpanelapi/MixpanelAPI.java |
Added Builder pattern and refactored constructors to use unified private constructor with JsonSerializer support |
src/main/java/com/mixpanel/mixpanelapi/internal/JsonSerializer.java |
Removed getImplementationName() method to simplify interface |
src/main/java/com/mixpanel/mixpanelapi/internal/OrgJsonSerializer.java |
Removed getImplementationName() implementation |
src/main/java/com/mixpanel/mixpanelapi/internal/SerializerFactory.java |
Deleted automatic Jackson detection factory in favor of explicit configuration |
src/test/java/com/mixpanel/mixpanelapi/internal/SerializerBenchmark.java |
Removed benchmark utility (not part of production code) |
src/test/java/com/mixpanel/mixpanelapi/internal/JsonSerializerTest.java |
Updated tests to remove Jackson-specific tests and SerializerFactory tests |
src/test/java/com/mixpanel/mixpanelapi/MixpanelAPITest.java |
Added comprehensive tests for Builder pattern and all 8 public constructors |
pom.xml |
Removed optional Jackson dependency, updated version to 1.6.0 |
mixpanel-java-extension-jackson/pom.xml |
New extension module POM with jackson-core dependency |
mixpanel-java-extension-jackson/src/main/java/com/mixpanel/mixpanelapi/internal/JacksonSerializer.java |
High-performance Jackson streaming API implementation |
mixpanel-java-extension-jackson/src/test/java/com/mixpanel/mixpanelapi/internal/JacksonSerializerTest.java |
Tests verifying Jackson output matches OrgJson output exactly using JSONAssert |
mixpanel-java-extension-jackson/README.md |
Documentation for Jackson extension module with installation and usage instructions |
README.md |
Updated all examples to use Builder pattern, documented Jackson extension usage |
.github/workflows/release.yml |
Enhanced to build, test, and deploy both main SDK and Jackson extension artifacts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| String jacksonResult = jacksonSerializer.serializeArray(messages); | ||
| String orgResult = orgSerializer.serializeArray(messages); | ||
|
|
||
| jacksonResult = jacksonSerializer.serializeArray(messages); |
Copilot
AI
Nov 26, 2025
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.
Redundant serialization call. Line 36 already calls jacksonSerializer.serializeArray(messages) and stores the result in jacksonResult. Line 39 repeats the same call unnecessarily.
Remove line 39:
String jacksonResult = jacksonSerializer.serializeArray(messages);
String orgResult = orgSerializer.serializeArray(messages);
JSONArray array = new JSONArray(jacksonResult);| jacksonResult = jacksonSerializer.serializeArray(messages); |
Builder Pattern and Jackson Extension for Mixpanel Java SDK
Overview
This PR introduces a flexible Builder pattern for MixpanelAPI configuration and adds an optional high-performance Jackson serialization extension as a separate module.
Key Changes
1. Builder Pattern Implementation
MixpanelAPI.Builderclass providing fluent API for configurationExample:
2. JSON Serializer Abstraction
JsonSerializerinterface incom.mixpanel.mixpanelapi.internalpackageOrgJsonSerializer- default implementation using org.json library (maintains backward compatibility)3. Jackson Extension Module (mixpanel-java-extension-jackson)
JacksonSerializerimplementation using Jackson streaming APIjackson-coredependency (lightweight)Performance Benefits:
/importendpoint (up to 2000 events)Usage:
4. Testing
JacksonSerializerTestuses JSONAssert to verify Jackson output matches OrgJson output exactly5. Release Infrastructure
6. Documentation Updates
Breaking Changes
None. All existing constructors and APIs remain unchanged. This is a purely additive release.
Migration Guide
Users can optionally adopt the builder pattern:
Before:
After: